Another crash on exit with gcc (MinGW)

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: Another crash on exit with gcc (MinGW)

Post by drfrag »

Okay, i've applied a workaround to prevent the crash and it only works when removing the thread_local keyword at the same time. For now i've stashed the hack and only made the GlobalVMStack variable non thread_local.
This is my hack, i make some objects NULL leaking memory on exit:

Code: Select all

 src/c_cmds.cpp               | 10 ++++++++++
 src/scripting/vm/vmframe.cpp | 11 +++++++++++
 src/win32/st_start.cpp       |  8 ++++++++
 3 files changed, 29 insertions(+)

diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp
index 8e8612dec..488148a60 100644
--- a/src/c_cmds.cpp
+++ b/src/c_cmds.cpp
@@ -77,6 +77,10 @@
 extern FILE *Logfile;
 extern bool insave;
 
+#ifdef __MINGW32__
+extern bool exiting; // for MinGW
+#endif
+
 CVAR (Bool, sv_cheats, false, CVAR_SERVERINFO | CVAR_LATCH)
 CVAR (Bool, sv_unlimited_pickup, false, CVAR_SERVERINFO)
 
@@ -100,11 +104,17 @@ bool CheckCheatmode (bool printmsg)
 
 CCMD (quit)
 {
+#ifdef __MINGW32__
+	exiting = true;
+#endif
 	if (!insave) exit (0);
 }
 
 CCMD (exit)
 {
+#ifdef __MINGW32__
+	exiting = true;
+#endif
 	if (!insave) exit (0);
 }
 
diff --git a/src/scripting/vm/vmframe.cpp b/src/scripting/vm/vmframe.cpp
index 69a6febbf..8d8c26e1a 100644
--- a/src/scripting/vm/vmframe.cpp
+++ b/src/scripting/vm/vmframe.cpp
@@ -41,6 +41,10 @@
 #include "vmintern.h"
 #include "types.h"
 
+#ifdef __MINGW32__
+extern bool exiting; // for MinGW
+#endif
+
 cycle_t VMCycles[10];
 int VMCalls[10];
 
@@ -243,6 +247,13 @@ VMFrameStack::VMFrameStack()
 
 VMFrameStack::~VMFrameStack()
 {
+#ifdef __MINGW32__
+	if (exiting) // hack hack
+	{
+		Blocks = NULL;
+		UnusedBlocks = NULL;
+	}
+#endif
 	while (PopFrame() != NULL)
 	{ }
 	if (Blocks != NULL)
diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp
index aa0ce9a03..e6bd46e92 100644
--- a/src/win32/st_start.cpp
+++ b/src/win32/st_start.cpp
@@ -119,6 +119,10 @@
 
 // TYPES -------------------------------------------------------------------
 
+#ifdef __MINGW32__
+bool exiting = false; // for MinGW
+#endif
+
 class FBasicStartupScreen : public FStartupScreen
 {
 public:
@@ -1093,6 +1097,10 @@ void FStrifeStartupScreen::DrawStuff(int old_laser, int new_laser)
 
 void ST_Endoom()
 {
+#ifdef __MINGW32__
+	exiting = true;
+#endif
+
 	if (showendoom == 0) exit(0);
 
 	if (gameinfo.Endoom.Len() == 0)
So what do you think? Simple and elegant right? :mrgreen:
This is what happens when i keep the variable thread_local:

Code: Select all

#4  0x0042ca38 in ST_Endoom () at C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100
C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100:32931:beg:0x42ca38
In (anonymous namespace)::run() () ()
In msvcrt!_flushall () (C:\Windows\system32\msvcrt.dll)
In msvcrt!.p.iob () (C:\Windows\system32\msvcrt.dll)
In ntdll!RtlDecodePointer () (C:\Windows\SYSTEM32\ntdll.dll)
In msvcrt!.p.iob () (C:\Windows\system32\msvcrt.dll)
In msvcrt!_flushall () (C:\Windows\system32\msvcrt.dll)
In msvcrt!.p.iob () (C:\Windows\system32\msvcrt.dll)
In ntdll!RtlDecodePointer () (C:\Windows\SYSTEM32\ntdll.dll)
In msvcrt!.p.iob () (C:\Windows\system32\msvcrt.dll)
In msvcrt!_flushall () (C:\Windows\system32\msvcrt.dll)
In msvcrt!_CallMemberFunction0 () (C:\Windows\system32\msvcrt.dll)
#2  0x0042ca38 in ST_Endoom () at C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100
C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100:32931:beg:0x42ca38
At C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100
#2  0x0042ca38 in ST_Endoom () at C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100
C:\DEV\vsqzdoom\src\win32\st_start.cpp:1100:32931:beg:0x42ca38
In RaiseException () (C:\Windows\system32\KernelBase.dll)
[Inferior 1 (process 4196) exited with code 0377]
I've reported the crash as a bug in the MinGW C runtime here: https://sourceforge.net/p/mingw-w64/bugs/734/
So i think this can be closed now as not ZDoom.
Post Reply

Return to “General”