Skip to content

Commit ef1039d

Browse files
committed
Make Asar app also run in thread
1 parent e844d45 commit ef1039d

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/asar/asar.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ const char* get_current_block();
180180
// interface to make use of the full callstack.
181181
const char* get_previous_file_name();
182182
int get_previous_file_line_no();
183+
184+
// RPG Hacker: This is currently disabled for debug builds, because it causes random crashes
185+
// when used in combination with -fsanitize=address.
186+
#if defined(_WIN32) && defined(NDEBUG)
187+
# define RUN_VIA_FIBER
188+
#else
189+
# define RUN_VIA_THREAD
190+
#endif

src/asar/interface-cli.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "assembleblock.h"
77
#include "asar_math.h"
88
#include "unicode.h"
9+
#include "platform/thread-helpers.h"
910

1011
#if defined(windows)
1112
# define NOMINMAX
@@ -541,18 +542,29 @@ int main(int argc, const char * argv[])
541542
string stddefinespath = STR dir(argv[0]) + "stddefines.txt";
542543
parse_std_defines(stddefinespath);
543544

544-
for (pass=0;pass<3;pass++)
545+
auto execute_patch = [&]()
545546
{
546-
//pass 1: find which bank all labels are in, for label optimizations
547-
// freespaces are listed as above 0xFFFFFF, to find if it's in the ROM or if it's dynamic
548-
//pass 2: find where exactly all labels are
549-
//pass 3: assemble it all
550-
initstuff();
551-
assemblefile(asmname);
552-
// RPG Hacker: Necessary, because finishpass() can throws warning and errors.
553-
callstack_push cs_push(callstack_entry_type::FILE, filesystem->create_absolute_path(nullptr, asmname));
554-
finishpass();
555-
}
547+
for (pass=0;pass<3;pass++)
548+
{
549+
//pass 1: find which bank all labels are in, for label optimizations
550+
// freespaces are listed as above 0xFFFFFF, to find if it's in the ROM or if it's dynamic
551+
//pass 2: find where exactly all labels are
552+
//pass 3: assemble it all
553+
initstuff();
554+
assemblefile(asmname);
555+
// RPG Hacker: Necessary, because finishpass() can throws warning and errors.
556+
callstack_push cs_push(callstack_entry_type::FILE, filesystem->create_absolute_path(nullptr, asmname));
557+
finishpass();
558+
}
559+
return true;
560+
};
561+
#if defined(RUN_VIA_FIBER)
562+
run_as_fiber(execute_patch);
563+
#elif defined(RUN_VIA_THREAD)
564+
run_as_thread(execute_patch);
565+
#else
566+
execute_patch();
567+
#endif
556568

557569
new_filesystem.destroy();
558570
filesystem = nullptr;

src/asar/interface-lib.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
#define EXPORT extern "C" __attribute__ ((visibility ("default")))
2020
#endif
2121

22-
// RPG Hacker: This is currently disabled for debug builds, because it causes random crashes
23-
// when used in combination with -fsanitize=address.
24-
#if defined(_WIN32) && defined(NDEBUG)
25-
# define RUN_VIA_FIBER
26-
#else
27-
# define RUN_VIA_THREAD
28-
#endif
29-
3022
static autoarray<const char *> prints;
3123
static string symbolsfile;
3224
static int numprint;

0 commit comments

Comments
 (0)