Skip to content

Commit c43a943

Browse files
committed
fix LevelListProxy::getItemType logic
1 parent 7d26e9c commit c43a943

File tree

7 files changed

+169
-17
lines changed

7 files changed

+169
-17
lines changed

CMakeLists.txt

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,33 @@ find_package(Qt5 COMPONENTS Core Gui Test Widgets WebEngineWidgets Sql REQUIRED)
1818

1919
find_package(CURL REQUIRED)
2020

21+
# Add miniz as a subdirectory
2122
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt")
2223
message(STATUS "Submodule 'libs/miniz' not found. Updating submodules...")
2324
execute_process(
2425
COMMAND git submodule update --init --recursive
2526
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
2627
)
27-
file(READ "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt" cmake)
28+
file(READ "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt" MINIZ_CMAKE)
2829
string(REPLACE "cmake_minimum_required(VERSION 3.5)"
29-
"cmake_minimum_required(VERSION 3.16)" my_cmake "${cmake}")
30-
file(WRITE "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt" "${my_cmake}")
31-
endif()
32-
33-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/database/tombll.db")
34-
message(STATUS "Database not found, running get_trle.sh...")
35-
execute_process(
36-
COMMAND bash "${CMAKE_SOURCE_DIR}/database/get_trle.sh"
37-
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
30+
"cmake_minimum_required(VERSION 3.16)"
31+
NEW_MINIZ_CMAKE
32+
"${MINIZ_CMAKE}"
33+
)
34+
file(WRITE "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt"
35+
"${NEW_MINIZ_CMAKE}"
3836
)
3937
endif()
40-
4138
add_subdirectory(libs/miniz)
4239

4340
# Add LIEF as a subdirectory
41+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/LIEF/CMakeLists.txt")
42+
message(STATUS "Submodule 'libs/LIEF' not found. Updating submodules...")
43+
execute_process(
44+
COMMAND git submodule update --init --recursive
45+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
46+
)
47+
endif()
4448
set(LIEF_INSTALL OFF CACHE BOOL "Disable installation of LIEF")
4549
set(LIEF_EXAMPLES OFF)
4650
set(LIEF_TESTS OFF)
@@ -51,18 +55,52 @@ set(LIEF_PE ON)
5155
set(LIEF_MACHO OFF)
5256
set(LIEF_DEX OFF)
5357
set(LIEF_ART OFF)
58+
add_subdirectory(libs/LIEF)
5459

55-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/LIEF/CMakeLists.txt"
56-
AND NOT NO_DATABASE
60+
# Add libbacktrace as a subdirectory
61+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/libbacktrace/configure")
62+
message(STATUS
63+
"Submodule 'libs/libbacktrace' not found. Updating submodules..."
5764
)
58-
message(STATUS "Submodule 'libs/LIEF' not found. Updating submodules...")
5965
execute_process(
6066
COMMAND git submodule update --init --recursive
6167
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
6268
)
6369
endif()
70+
if(EXISTS "${CMAKE_SOURCE_DIR}/libs/libbacktrace/configure")
71+
message(STATUS "Running autoconf to prepare libbacktrace")
72+
execute_process(
73+
COMMAND bash "${CMAKE_SOURCE_DIR}/libs/libbacktrace/configure"
74+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/libs/libbacktrace"
75+
RESULT_VARIABLE AUTOCONF_RESULT
76+
)
77+
if(NOT AUTOCONF_RESULT EQUAL 0)
78+
message(
79+
FATAL_ERROR
80+
"Autoconf failed with exit code ${AUTOCONF_RESULT}"
81+
)
82+
endif()
83+
execute_process(
84+
COMMAND make
85+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/libs/libbacktrace"
86+
RESULT_VARIABLE MAKE_RESULT
87+
)
88+
if(NOT MAKE_RESULT EQUAL 0)
89+
message(
90+
FATAL_ERROR
91+
"Make failed with exit code ${MAKE__RESULT}"
92+
)
93+
endif()
94+
endif()
6495

65-
add_subdirectory(libs/LIEF)
96+
97+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/database/tombll.db")
98+
message(STATUS "Database not found, running get_trle.sh...")
99+
execute_process(
100+
COMMAND bash "${CMAKE_SOURCE_DIR}/database/get_trle.sh"
101+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
102+
)
103+
endif()
66104

67105
set(SOURCES_TESTS
68106
test/test.hpp
@@ -93,6 +131,7 @@ set(SOURCES_MC
93131
src/PyRunner.hpp
94132
src/Runner.cpp
95133
src/Runner.hpp
134+
src/assert.hpp
96135
src/binary.hpp
97136
src/binary.cpp
98137
src/main.cpp
@@ -114,6 +153,7 @@ set(LINK_COMMON
114153
miniz
115154
LIEF::LIEF
116155
${CURL_LIBRARY}
156+
"${CMAKE_SOURCE_DIR}/libs/libbacktrace/.libs/libbacktrace.a"
117157
)
118158

119159
set(LINK_GUI
@@ -124,6 +164,7 @@ set(INCLUDE_DIR
124164
${CURL_INCLUDE_DIR}
125165
libs/miniz
126166
libs/LIEF/include
167+
libs/libbacktrace
127168
src
128169
)
129170

setup_nvim_lsp.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ cmake \
1515
cd ..
1616

1717
git config submodule.libs/miniz.ignore all
18+
git config submodule.libs/libbacktrace.ignore all
1819

1920
./build.sh

src/Data.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <QSqlError>
2626
#include <QSqlQuery>
2727

28+
#include "../src/assert.hpp"
29+
2830
/**
2931
* @struct FileListItem
3032
* @brief Files object to keep track of files.
@@ -251,26 +253,32 @@ struct ListItemData {
251253

252254

253255
void setGameId(const qint64 id) {
256+
Q_ASSERT_WITH_TRACE(id != 0);
254257
m_game_id = id;
255258
}
256259

257260
void setLid(const qint64 id) {
261+
Q_ASSERT_WITH_TRACE(id != 0);
258262
m_trle_id = id;
259263
}
260264

261265
void setTitle(const QString& title) {
266+
Q_ASSERT_WITH_TRACE(!title.isEmpty());
262267
m_title = title;
263268
}
264269

265270
void setAuthors(const QStringList& authors) {
271+
Q_ASSERT_WITH_TRACE(!authors.isEmpty());
266272
m_authors = authors;
267273
}
268274

269275
void setShortBody(const QString& shortBody) {
276+
Q_ASSERT_WITH_TRACE(!shortBody.isEmpty());
270277
m_shortBody = shortBody;
271278
}
272279

273280
void setType(const qint64 type) {
281+
Q_ASSERT_WITH_TRACE(type != 0);
274282
m_type = type;
275283
}
276284

@@ -287,6 +295,7 @@ struct ListItemData {
287295
}
288296

289297
void setReleaseDate(const QString& releaseDate) {
298+
Q_ASSERT_WITH_TRACE(!releaseDate.isEmpty());
290299
m_releaseDate = releaseDate;
291300
}
292301

src/LevelViewList.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ quint64 LevelListProxy::getLid(const QModelIndex &i) {
103103
if (id == 0) {
104104
id = sourceModel()->data(i, Qt::UserRole+10).toInt();
105105
}
106+
Q_ASSERT_WITH_TRACE(id != 0);
106107
return id;
107108
}
108109

109110
bool LevelListProxy::getItemType(const QModelIndex &i) {
110-
return sourceModel()->data(i, Qt::UserRole+10).toBool();
111+
return sourceModel()->data(i, Qt::UserRole+1).toBool();
111112
}
112113

113114
bool LevelListProxy::getInstalled(const QModelIndex &i) {

src/Model.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "../src/Model.hpp"
1515
#include "../src/Data.hpp"
1616
#include "../src/Path.hpp"
17+
#include "../src/assert.hpp"
18+
#include <qglobal.h>
1719

1820
Model::Model() {}
1921
Model::~Model() {}
@@ -283,7 +285,7 @@ bool Model::setLink(int id) {
283285
void Model::setupGame(int id) {
284286
QVector<FileListItem> list = data.getFileList(id);
285287
const size_t s = list.size();
286-
assert(s != 0);
288+
Q_ASSERT_WITH_TRACE(s != 0);
287289
Path from(Path::programFiles);
288290
Path to(Path::resource);
289291

src/TombRaiderLinuxLauncher.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ void TombRaiderLinuxLauncher::downloadClicked() {
499499
QModelIndex current = ui->listViewLevels->currentIndex();
500500
if (current.isValid()) {
501501
qint64 id = levelListProxy->getLid(current);
502+
qDebug() << "void TombRaiderLinuxLauncher" <<
503+
"::downloadClicked() quint64 id: " << id;
502504
if (levelListProxy->getItemType(current)) {
503505
ui->listViewLevels->setEnabled(false);
504506
ui->progressBar->setValue(0);

src/assert.hpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* TombRaiderLinuxLauncher
2+
* Martin Bångens Copyright (C) 2025
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*/
13+
14+
#ifndef SRC_ASSERT_HPP_
15+
#define SRC_ASSERT_HPP_
16+
17+
#include <QtGlobal>
18+
#include <cstdio>
19+
#include <cstdlib>
20+
#include <string>
21+
#include <cxxabi.h>
22+
#include <backtrace.h>
23+
#include <backtrace-supported.h>
24+
#include <signal.h>
25+
#include <sys/resource.h>
26+
27+
// --- libbacktrace helpers ---
28+
static backtrace_state* g_bt_state = nullptr;
29+
30+
static void bt_error_callback(void*, const char* msg, int errnum) {
31+
fprintf(stderr, "libbacktrace error: %s (err=%d)\n", msg, errnum);
32+
}
33+
34+
static int bt_full_callback(void* data,
35+
uintptr_t /*pc*/,
36+
const char* filename,
37+
int lineno,
38+
const char* function) {
39+
bool* first_frame = static_cast<bool*>(data);
40+
41+
// Skip our assert wrapper and ?? frames
42+
if (!filename || !function)
43+
return 0;
44+
if (std::string(filename).find("assert.hpp") != std::string::npos)
45+
return 0;
46+
47+
const char* pretty = function ? function : "??";
48+
char* demangled = nullptr;
49+
int status = 0;
50+
if (function) {
51+
demangled = abi::__cxa_demangle(function, nullptr, nullptr, &status);
52+
if (status == 0 && demangled)
53+
pretty = demangled;
54+
}
55+
56+
fprintf(stderr, "%s %s:%d: %s\n",
57+
(*first_frame ? "-->" : " "),
58+
filename,
59+
lineno,
60+
pretty);
61+
62+
*first_frame = false;
63+
free(demangled);
64+
return 0;
65+
}
66+
67+
inline void print_stacktrace() {
68+
#ifdef BACKTRACE_SUPPORTED
69+
if (!g_bt_state) {
70+
g_bt_state = backtrace_create_state(nullptr, 1, bt_error_callback, nullptr);
71+
}
72+
bool first_frame = true;
73+
backtrace_full(g_bt_state, 0, bt_full_callback, bt_error_callback, &first_frame);
74+
#else
75+
fprintf(stderr, "Backtrace not supported on this build.\n");
76+
#endif
77+
}
78+
79+
// --- Qt-safe assert with trace ---
80+
#define Q_ASSERT_WITH_TRACE(cond) \
81+
do { \
82+
if (!(cond)) { \
83+
fprintf(stderr, "ASSERT: \"%s\" in file %s, line %d\n", \
84+
#cond, __FILE__, __LINE__); \
85+
print_stacktrace(); \
86+
fflush(stderr); \
87+
struct rlimit rl{}; \
88+
rl.rlim_cur = 0; \
89+
rl.rlim_max = 0; \
90+
setrlimit(RLIMIT_CORE, &rl); \
91+
signal(SIGABRT, SIG_DFL); \
92+
abort(); \
93+
} \
94+
} while (0)
95+
96+
#endif // SRC_ASSERT_HPP_

0 commit comments

Comments
 (0)