Skip to content

Commit f9b8b0f

Browse files
authored
Fix crashing on Linux (#69)
* Update toml11 * Update spdlog * Prevent loading into child processes + detach thread
1 parent 06b9e74 commit f9b8b0f

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include_directories(glua_headers/include)
2222
include_directories(catch2/single_include)
2323

2424
# toml11
25-
include_directories(toml11)
25+
include_directories(toml11/single_include)
2626

2727
# gluasteal src
2828
add_subdirectory(src)

spdlog

Submodule spdlog updated 174 files

src/config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ void glt::config::LoadConfig() {
9999
logger->debug(
100100
"stealer.enabled = {}, stealer.write_mode = {}, loader.file = {}, logger.level = {}",
101101
cfg.stealer_enabled,
102-
cfg.stealer_write_mode,
102+
static_cast<int>(cfg.stealer_write_mode),
103103
cfg.loader_file,
104-
cfg.logger_level
104+
spdlog::level::to_string_view(cfg.logger_level)
105105
);
106106
}
107107
catch (const std::exception& ex) {

src/main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,26 @@ void* InitWrap(void*) {
2626
return nullptr;
2727
}
2828

29-
int __attribute__((constructor)) main() {
29+
bool is_game_process() {
30+
std::string proc_name = program_invocation_short_name;
31+
32+
return proc_name == "gmod" || proc_name == "hl2_linux";
33+
}
34+
35+
void __attribute__((constructor)) glt_main() {
36+
if (!is_game_process()) {
37+
return;
38+
}
39+
3040
pthread_t th;
3141
pthread_create(&th, NULL, InitWrap, NULL);
32-
33-
return 0;
42+
pthread_detach(th);
3443
}
3544

36-
int __attribute__((destructor)) kill() {
45+
int __attribute__((destructor)) glt_kill() {
3746
return 0;
3847
}
48+
3949
#endif
4050

4151

toml11

Submodule toml11 updated 307 files

0 commit comments

Comments
 (0)