From 94aae077d3f936ad299cc7f428de1b06176856bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=86=E2=9C=A0Sa=CD=A5b=CD=A3e=CD=ABr=F0=9F=91=91?= =?UTF-8?q?=E2=B0=80?= Date: Tue, 7 Mar 2023 00:56:20 +0800 Subject: [PATCH] Fixes segfault on closing app * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x000000010070ef98 QtWidgets`QApplication::~QApplication() + 564 QtWidgets`QApplication::~QApplication: -> 0x10070ef98 <+564>: ldr x0, [x0] 0x10070ef9c <+568>: str x20, [x8] 0x10070efa0 <+572>: ldr w8, [x0, #0x10] 0x10070efa4 <+576>: cmn w8, #0x1 Target 0: (HexGenerator) stopped. (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) * frame #0: 0x000000010070ef98 QtWidgets`QApplication::~QApplication() + 564 frame #1: 0x000000010070f128 QtWidgets`QApplication::~QApplication() + 12 frame #2: 0x0000000100042248 HexGenerator`std::__1::unique_ptr >::~unique_ptr() + 40 frame #3: 0x00000001af27ffd8 libsystem_c.dylib`__cxa_finalize_ranges + 464 frame #4: 0x00000001af27fd6c libsystem_c.dylib`exit + 44 frame #5: 0x00000001af3aef7c libdyld.dylib`dyld4::LibSystemHelpers::exit(int) const + 20 frame #6: 0x00000001af06be9c dyld`start + 2620 --- HexGenerator/Source/Main.cpp | 7 ++++--- HexGenerator/Source/Tools/Tools.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/HexGenerator/Source/Main.cpp b/HexGenerator/Source/Main.cpp index 71737e71b..d4216bc3f 100644 --- a/HexGenerator/Source/Main.cpp +++ b/HexGenerator/Source/Main.cpp @@ -16,7 +16,7 @@ namespace PokemonAutomation{ namespace HexGenerator{ -std::unique_ptr application; +QApplication* application = nullptr; } } @@ -27,7 +27,8 @@ using namespace HexGenerator; int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - application.reset(new QApplication(argc, argv)); + auto app = std::make_unique(argc, argv); + application = app.get(); settings.load(); @@ -57,7 +58,7 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); - int ret = application->exec(); + int ret = app->exec(); settings.write(); return ret; } diff --git a/HexGenerator/Source/Tools/Tools.h b/HexGenerator/Source/Tools/Tools.h index b9e057d03..05881f034 100644 --- a/HexGenerator/Source/Tools/Tools.h +++ b/HexGenerator/Source/Tools/Tools.h @@ -37,11 +37,11 @@ int build_hexfile( -extern std::unique_ptr application; +extern QApplication* application; template void run_on_main_thread(Lambda&& lambda){ - QMetaObject::invokeMethod(application.get(), std::move(lambda)); + QMetaObject::invokeMethod(application, std::move(lambda)); }