godot: Crash on exit with a StyleBox configured in Godot Inspector or referenced in C# scripts
Tested versions
- Reproducable in every godot 4.x version
System information
Godot v4.2.1.stable.mono - Windows 10.0.19044 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 (NVIDIA; 31.0.15.3623) - AMD Ryzen 5 2600X Six-Core Processor (12 Threads)
Issue description
I export the game with Godot 4.2.1 (it happens with all 4.x versions) and when I start the game it runs fine. If I immediately quit the game GetTree().Quit() has no issues. When I play the game for a little while (5 mins or so). I always get an memory access violation.
There are no errors when I launch the game via CMD with -verbose. I only get this, which is clean.
However Windows Event Viewer will log an error in the application logs:
I understand that this has to do with a memory access violation. I am using C# and I am not manually setting pointers or handling threads. I have the most detailed Exception Analysis from WinDBG but it points to Embree, a high-performance ray tracing kernel library, which is part of the call stack (STR_exe!ZN6embree13TaskScheduler12startThreadsEv). Below I will share the entire analysis:
*******************************************************************************
* *
* Exception Analysis *
* *
*******************************************************************************
Failed to request MethodData, not in JIT code range
KEY_VALUES_STRING: 1
Key : AV.Fault
Value: Read
Key : Analysis.CPU.mSec
Value: 1358
Key : Analysis.Elapsed.mSec
Value: 1755
Key : Analysis.IO.Other.Mb
Value: 15
Key : Analysis.IO.Read.Mb
Value: 19
Key : Analysis.IO.Write.Mb
Value: 45
Key : Analysis.Init.CPU.mSec
Value: 2562
Key : Analysis.Init.Elapsed.mSec
Value: 1836728
Key : Analysis.Memory.CommitPeak.Mb
Value: 167
Key : CLR.Engine
Value: CORECLR
Key : CLR.Version
Value: 6.0.1823.26907
Key : Failure.Bucket
Value: INVALID_POINTER_READ_c0000005_godot.windows.template_debug.x86_64.mono.exe!Unknown
Key : Failure.Hash
Value: {859a067d-44f2-ebb7-58a6-4b0d9775d1cf}
Key : Timeline.OS.Boot.DeltaSec
Value: 212757
Key : Timeline.Process.Start.DeltaSec
Value: 1837
Key : WER.OS.Branch
Value: vb_release
Key : WER.OS.Version
Value: 10.0.19041.1
Key : WER.Process.Version
Value: 1.0.0.0
PROCESSES_ANALYSIS: 1
SERVICE_ANALYSIS: 1
STACKHASH_ANALYSIS: 1
ADDITIONAL_XML: 1
OS_BUILD_LAYERS: 1
TIMELINE_ANALYSIS: 1
Timeline: !analyze.Start
Name: <blank>
Time: 2023-12-16T09:33:12.636Z
Diff: 363 mSec
Timeline: Dump.Current
Name: <blank>
Time: 2023-12-16T09:33:13.0Z
Diff: 0 mSec
Timeline: Process.Start
Name: <blank>
Time: 2023-12-16T09:02:36.0Z
Diff: 1837000 mSec
Timeline: OS.Boot
Name: <blank>
Time: 2023-12-13T22:27:16.0Z
Diff: 212757000 mSec
DUMP_CLASS: 2
DUMP_QUALIFIER: 0
MODLIST_WITH_TSCHKSUM_HASH: 11a0549b88b871768ce3e285ead0143a685d5b30
MODLIST_SHA1_HASH: 2f48b3469ef4515754ecbd44722180bde4f46ca7
NTGLOBALFLAG: 70
PROCESS_BAM_CURRENT_THROTTLED: 0
PROCESS_BAM_PREVIOUS_THROTTLED: 0
APPLICATION_VERIFIER_FLAGS: 0
PRODUCT_TYPE: 1
SUITE_MASK: 272
DUMP_TYPE: fe
FAULTING_IP:
godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+2d7c49f
00007ff7`1e4fb7ff 488b01 mov rax,qword ptr [rcx]
EXCEPTION_RECORD: (.exr -1)
ExceptionAddress: 00007ff71e4fb7ff (godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+0x0000000002d7c49f)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000000
Parameter[1]: ffffffffffffffff
Attempt to read from address ffffffffffffffff
FAULTING_THREAD: 00005188
DEFAULT_BUCKET_ID: INVALID_POINTER_READ
PROCESS_NAME: godot.windows.template_debug.x86_64.mono.exe
FOLLOWUP_IP:
godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+264d13f
00007ff7`1ddcc49f 7eff jle godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+0x264d140 (00007ff7`1ddcc4a0)
READ_ADDRESS: ffffffffffffffff
ERROR_CODE: (NTSTATUS) 0xc0000005 - De instructie op 0x%p verwijst naar geheugen op 0x%p. Het geheugen kan niet worden %s.
EXCEPTION_CODE_STR: c0000005
EXCEPTION_PARAMETER1: 0000000000000000
EXCEPTION_PARAMETER2: ffffffffffffffff
WATSON_BKT_PROCSTAMP: 0
WATSON_BKT_PROCVER: 1.0.0.0
PROCESS_VER_PRODUCT: game
WATSON_BKT_MODULE: godot.windows.template_debug.x86_64.mono.exe
WATSON_BKT_MODSTAMP: 0
WATSON_BKT_MODOFFSET: 34ab7ff
WATSON_BKT_MODVER: 1.0.0.0
MODULE_VER_PRODUCT: game
BUILD_VERSION_STRING: 19041.1.amd64fre.vb_release.191206-1406
ANALYSIS_SESSION_HOST: DESKTOP-OG38IEJ
ANALYSIS_SESSION_TIME: 12-16-2023 10:33:12.0636
ANALYSIS_VERSION: 10.0.25921.1001 amd64fre
MANAGED_CODE: 1
MANAGED_ENGINE_MODULE: coreclr
MANAGED_ANALYSIS_PROVIDER: SOS
MANAGED_THREAD_ID: 5188
THREAD_ATTRIBUTES:
[ GLOBAL ]
Global D1 PID: [14600]
Global D1 Thread_Count: [36]
Global D1 PageSize: [4096]
Global STR ModList_SHA1_Hash: [2f48b3469ef4515754ecbd44722180bde4f46ca7]
Global STR CommandLine: [C:\Users\Benardus\Documents\GAME\GAME.exe]
Global STR Desktop_Name: [WinSta0\Default]
Global STR ProcessName: [godot.windows.template_debug.x86_64.mono.exe]
Global STR Debugger_CPU_Architecture: [amd64]
Global D1 CPU_ProcessorCount: [12]
Global D1 CPU_MHZ: [3600]
Global STR CPU_Architecture: [X64]
Global D1 CPU_Family: [23]
Global D1 CPU_Model: [8]
Global D1 CPU_Stepping: [2]
Global STR CPU_VendorString: []
Global ManagedFailure
Global D1 LoadedModule_Count: [100]
Global D1 UnloadedModule_Count: [3]
Global ProcessBeingDebugged
Global D1 GFlags: [112]
Global D1 Application_Verifer_Flags: [0]
Global STR CurrentTimeDate: [2023-12-16T09:33:13.0Z]
Global D1 CurrentTimeDate: [-473886080]
Global STR ProcessUpTime: [0 days 0:30:37.000]
Global D1 ProcessUpTime: [1837]
Global STR SystemUpTime: [2 days 11:05:57.000]
Global D1 SystemUpTime: [212757]
Global D1 ProductType: [1]
Global D1 SuiteMask: [272]
Global ASLR_Enabled
Global SafeSEH_Enabled
Global SafeSEH_NotApplicable
[ THREAD ]
0 Id: 3908.5188
Frame[00] D1 TID: [0x5188]
Frame[00] Is_OriginalExceptionThread
Frame[00] D1 Stack_Frames_Extraction_Time_(ms): [0x10]
Frame[00] STR ThreadStartAddress: [godot_windows_template_debug_x86_64_mono+0x13d0]
Frame[00] D1 ThreadStartAddress: [0x00007ff71b0513d0]
Frame[00] STR Stack_SHA1_Hash_Mod: [441073e2af01e5c355fa2ce8b8c581fe2ba3b6f8]
Frame[00] D2 Stack_SHA1_Hash_Mod: [0xa]
Frame[00] STR Stack_SHA1_Hash_Unique_Mod: [53f6829ecc5643a0832019b563205bb05c2b7c75]
Frame[00] D2 Stack_SHA1_Hash_Unique_Mod: [0xa]
Frame[00] STR Stack_SHA1_Hash_Mod_Func: [4d82e87690028930adcfd1234760a7efbce4aa96]
Frame[00] D2 Stack_SHA1_Hash_Mod_Func: [0xa]
Frame[00] STR Stack_SHA1_Hash_Mod_Func_Offset: [d799d3d7adb7b9e098d73bb1dcd295cff457f7d6]
Frame[00] D2 Stack_SHA1_Hash_Mod_Func_Offset: [0xa]
Frame[00] STR FrameGroupHash: [8cc2e7e12b2844370aa4c03db213167b41db9283]
Frame[00] D2 FrameGroupHash: [0x7]
Frame[08] STR FrameGroupHash: [7ea492feb1419c00d39d38bbc95ba05900031a09]
Frame[08] D2 FrameGroupHash: [0x8]
Frame[09] STR FrameGroupHash: [0b0cefc38e6086cebb12d6063da67f39c688ae78]
Frame[09] D2 FrameGroupHash: [0x9]
Frame[00] D1 Number_of_Unique_Stack_Modules: [0x3]
Frame[08] CompleteStackWalk
Frame[00] Is_UIThread
Frame[00] D1 Thread_LastStatus: [0xc0000034]
Frame[00] D1 ThreadLocale: [0x413]
Frame[00] D1 BadReadAddress: [0xffffffffffffffff]
Frame[00] D1 MinusOne_READ: [0xffffffffffffffff]
Frame[00] D1 Number_of_Stack_Frames: [0xa]
Frame[00] D1 Bad_Frame_Count: [0x0]
Frame[00] D1 Ignored_Frame_Count: [0x0]
Frame[00] D1 Frames_not_in_stack_range: [0x0]
Frame[00] NotSysEnter
Frame[00] Is_ManagedThread
Frame[00] Is_SuspectHighUserTime
Frame[00] Is_DefiniteHighUserTime
Frame[00] Is_SuspectHighKernelTime
Frame[00] D1 Arch_AX_Register: [0x000002a4d66e7da0]
Frame[00] D1 Arch_BX_Register: [0xfeeefeeefeeefeee]
Frame[00] D1 Arch_CX_Register: [0xfeeefeeefeeefeee]
Frame[00] D1 LoadedModule_Arch_DX: [0x00007ff71e57d6b8]
Frame[00] null_Arch_SI
Frame[00] null_Arch_DI
Frame[00] D1 stackaddr_SP: [0x000000d0327ff360]
Frame[00] D1 LoadedModule_Arch_BP: [0x00007ff71e57d6b8]
Frame[00] D1 LoadedModule_Arch_IP: [0x00007ff71e4fb7ff]
Frame[00] D1 loadedmodule_msr_r8: [0x00007ff71e573518]
Frame[00] NULL_msr_r9
Frame[00] D1 msr_r10: [0x000002a46d2c0000]
Frame[00] D1 stackaddr_msr_r11: [0x000000d0327ff430]
Frame[00] D1 loadedmodule_msr_r12: [0x00007ff71e573518]
Frame[00] D1 Near_NULL_msr_r13: [0x0000000000000001]
Frame[00] NULL_msr_r14
Frame[00] NULL_msr_r15
Frame[00] D1 Instruction_Pointer: [0x00007ff71e4fb7ff]
Frame[00] D1 read_Arch_CX: [0xfeeefeeefeeefeee]
Frame[00] IP_Biased
Frame[00] D1 Stack_Attribute_Extraction_Time_(ms): [0x1f]
Frame[00] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x2d7c49f]
Frame[01] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x4e8248]
Frame[02] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x21fa394]
Frame[03] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x14116f2]
Frame[04] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x3cabe]
Frame[05] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x2d7c963]
Frame[06] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x12ee]
Frame[07] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x13e6]
Frame[08] Triage Symbol: [KERNEL32!BaseThreadInitThunk+0x14]
Frame[09] Triage Symbol: [ntdll!RtlUserThreadStart+0x21]
-1 Id: 3908.ffffffff
Frame[00] PSEUDO_THREAD
Frame[00] SINGLE_INSTRUCTION_PSEUDO_THREAD
Frame[00] Triage Symbol: [godot_windows_template_debug_x86_64_mono!+0x2d7c49f]
-1 Id: 3908.ffffffff
Frame[00] PSEUDO_THREAD
PRIMARY_PROBLEM_CLASS: APPLICATION_FAULT
PROBLEM_CLASSES:
ID: [0n329]
Type: [@ACCESS_VIOLATION]
Class: Addendum
Scope: BUCKET_ID
Name: Omit
Data: Omit
PID: [Unspecified]
TID: [0x5188]
Frame: [0] : godot_windows_template_debug_x86_64_mono
ID: [0n301]
Type: [INVALID_POINTER_READ]
Class: Primary
Scope: DEFAULT_BUCKET_ID (Failure Bucket ID prefix)
BUCKET_ID
Name: Add
Data: Omit
PID: [Unspecified]
TID: [0x5188]
Frame: [0] : godot_windows_template_debug_x86_64_mono
LAST_CONTROL_TRANSFER: from 00007ff71b538248 to 00007ff71e4fb7ff
STACK_TEXT:
000000d0`327ff360 00007ff7`1b538248 : 000000d0`327ff680 00000000`00000000 000002a4`0284ab90 000002a4`046347a0 : godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+0x2d7c49f
000000d0`327ff400 00007ff7`1d9796f4 : 000002a4`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : godot_windows_template_debug_x86_64_mono+0x4e8248
000000d0`327ff470 00007ff7`1cb90a52 : 00000000`00000000 00000000`00000000 00000000`ffffffff 000002a4`044f1280 : godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+0x21fa394
000000d0`327ff4d0 00007ff7`1b08cabe : 000000d0`327ff670 000000d0`00000000 000002a4`6d1eb4a0 000000d0`327ff680 : godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+0x14116f2
000000d0`327ff570 00007ff7`1e4fbcc3 : 000002a4`00000001 000000d0`327ffa6c 00000000`00000008 000002a4`6d2c1c50 : godot_windows_template_debug_x86_64_mono+0x3cabe
000000d0`327ffa40 00007ff7`1b0512ee : 00000000`00000000 00000000`0000002c 00007ff7`1f354ae8 00000000`00000000 : godot_windows_template_debug_x86_64_mono!ZN6embree13TaskScheduler12startThreadsEv+0x2d7c963
000000d0`327ffa90 00007ff7`1b0513e6 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : godot_windows_template_debug_x86_64_mono+0x12ee
000000d0`327ffae0 00007ffb`85e87034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : godot_windows_template_debug_x86_64_mono+0x13e6
000000d0`327ffb10 00007ffb`87e62651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
000000d0`327ffb40 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21
STACK_COMMAND: ~0s ; .cxr ; kb
FAULT_INSTR_CODE: 48018b48
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: godot_windows_template_debug_x86_64_mono+2d7c49f
FOLLOWUP_NAME: MachineOwner
MODULE_NAME: godot_windows_template_debug_x86_64_mono
IMAGE_NAME: godot.windows.template_debug.x86_64.mono.exe
DEBUG_FLR_IMAGE_TIMESTAMP: 0
FAILURE_BUCKET_ID: INVALID_POINTER_READ_c0000005_godot.windows.template_debug.x86_64.mono.exe!Unknown
BUCKET_ID: APPLICATION_FAULT_INVALID_POINTER_READ_godot_windows_template_debug_x86_64_mono+2d7c49f
FAILURE_EXCEPTION_CODE: c0000005
FAILURE_IMAGE_NAME: godot.windows.template_debug.x86_64.mono.exe
BUCKET_ID_IMAGE_STR: godot.windows.template_debug.x86_64.mono.exe
FAILURE_MODULE_NAME: godot_windows_template_debug_x86_64_mono
BUCKET_ID_MODULE_STR: godot_windows_template_debug_x86_64_mono
FAILURE_FUNCTION_NAME: Unknown
BUCKET_ID_FUNCTION_STR: Unknown
BUCKET_ID_OFFSET: 2d7c49f
BUCKET_ID_MODTIMEDATESTAMP: 0
BUCKET_ID_MODCHECKSUM: 41de9c2
BUCKET_ID_MODVER_STR: 1.0.0.0
BUCKET_ID_PREFIX_STR: APPLICATION_FAULT_INVALID_POINTER_READ_
FAILURE_PROBLEM_CLASS: APPLICATION_FAULT
FAILURE_SYMBOL_NAME: godot.windows.template_debug.x86_64.mono.exe!Unknown
OS_VERSION: 10.0.19041.1
OS_MAJOR: 10
OS_MINOR: 0
OS_BUILD: 19041
OS_REVISION: 1
BUILDDATESTAMP_STR: 191206-1406
OSBUILD_TIMESTAMP: 2019-12-06T14:06:00Z
BUILDLAB_STR: vb_release
OS_BUILD_STRING: 19041.1.amd64fre.vb_release.191206-1406
BUILDFLAVOR_STR: Checked
TARGET_TIME: 2023-12-16T09:33:14.000Z
OSSERVICEPACK: 0
OSPLATFORM_TYPE: x64
OSNAME: Windows 10
OSEDITION: Windows 10 WinNt SingleUserTS
SYSINFO:
<ANALYSIS>
<SYSMAN></SYSMAN>
<SYSMOD></SYSMOD>
<SYSMRK></SYSMRK>
</ANALYSIS>
FA_ADHOC:
<ANALYSIS>
<EXCEPTION_PARAMETER1>0</EXCEPTION_PARAMETER1>
<EXCEPTION_PARAMETER2>-1</EXCEPTION_PARAMETER2>
<BUILDFLAVOR_STR>Checked</BUILDFLAVOR_STR>
<OSPLATFORM_TYPE>x64</OSPLATFORM_TYPE>
</ANALYSIS>
IMAGE_VERSION: 1.0.0.0
ANALYSIS_SESSION_ELAPSED_TIME: 6db
ANALYSIS_SOURCE: UM
FAILURE_ID_HASH_STRING: um:invalid_pointer_read_c0000005_godot.windows.template_debug.x86_64.mono.exe!unknown
FAILURE_ID_HASH: {859a067d-44f2-ebb7-58a6-4b0d9775d1cf}
Followup: MachineOwner
Steps to reproduce
See the MRP with instructions
Minimal reproduction project (MRP)
Has been provided in a later comment in this thread: https://github.com/godotengine/godot/issues/86229#issuecomment-1860774596
Bugsquad edit: 20231218_MRP_StyleboxC#ReferenceCrash.zip
About this issue
- Original URL
- State: open
- Created 6 months ago
- Comments: 23 (9 by maintainers)
I have created a MRP and the exact same issue happens, your suggestion seems to be the root cause of the issue… 20231218_MRP_StyleboxC#ReferenceCrash.zip
Steps to reproduce:
It must be a faillure in my understanding. The scene in my game that sets that stylebox is destroyed and with that I believe the reference should die as well. I do not set this reference static or in a singleton. So I am surprised it holds on to that, again I must be misunderstanding something.
Thanks for your assistance.
I tested the MRP from https://github.com/godotengine/godot/issues/86229#issuecomment-1860774596 and was able to reproduce the crash on Linux (Fedora 39), albeit with difficulty. It took me around 20 attempts to get it to crash following the steps to reproduce.
I confirmed the crash both with 4.2.1.stable.mono and a custom editor build from the
master
branch, 4.3.dev.mono (9c626b623). Compiled withscons dev_build=yes dev_mode=yes linked=mold scu_build=all module_mono_enabled=yes
anddotnet-sdk-8.0
(8.0.101).Stacktrace:
Which is quite similar to the WinDbg one on https://github.com/godotengine/godot/issues/86229#issuecomment-1860604548
It’s not clear to me whether it’s ThemeDB’s destructor doing something wrong, or CSharpLanguage’s hold on instances.
CC @godotengine/dotnet
This is still an issue that needs to be solved, so unless it’s no longer reproducible, it shouldn’t be closed. The need of fixing engine issues isn’t scoped only to the original reporter / your project, other users might have the same issue and did not report it, or are waiting for this issue to be solved.
As for priorities, we do our best with very limited resources. It will be fixed eventually. If you absolutely need it fixed today, you can look to hire a consultant that would be able to fix it for you (and ideally contribute the fix back upstream via a PR).
Yes I agree, it has to be managed very carefully via code, be it GDscript or C#.
The problem is twofold:
Assigning styleboxes via code: Any stylebox referenced with code needs to be manually removed, this is manageable, albeit a bit unintuitive for non-memory managing languages. Especially since the Godot engine does take care of many other things itself (disconnecting signals, removing nodes etc). It would be ideal if GetTree().Quit() could manage this gracefully.
Assigning styleboxes via the editor: This is the biggest danger of this bug. Users of the editor will assign many things (nodes, settings, etc). Nearly all of these do not require the user to manually remove them via code, except for this stylebox. It is also insidious as the “crash” isn’t noticeable (most of the time it is a slight delay on quitting). It isn’t until you start digging in error logs that you find out something is seriously wrong. This is dangerous. You allow users to set this stylebox in the editor, but they need to remove it via code of which they are not informed, errors do not tell them this and it is unintuitive when nearly all other settings via the editor do not require this extra care. This will create serious complaints.
Solutions: A) Rewrite GetTree().Quit() to allow it to gracefully remove these references or atleast not cause a memory access violation when quitting. B) Remove the ability to assign styleboxes in the editor, because you’re going to have to manage them via code anyways. This is more of a workaround and people setting the styleboxes via code still need to go out of their way to remove the reference which almost no other setting/node/resource requires explicitely without good error logging. C) Print an error to the OS error log that informs the user that a stylebox was not unreferenced and caused a memory access violation. Also inform them that they need to unreference all styleboxes set in either the editor or via code, through C# or GDscript.
This is your own issue, you can edit the title yourself 😉
Update
Since removing all references in C# to styleboxes did not resolve my issue, I have taken the time to remove all styleboxes that I set in the inspector everywhere in my project. This has resolved the memory access violation. So I would suggest altering the title of this issue to something like: Crash on exit with Stylebox reference in Godot inspector AND/OR reference in C# scripts. Because it happens with either or. Hope this helps!
Okay, so the C# script holds a reference to some styleboxes and that’s what causes the crash on exit. We destroy the theme and all its contents before the scripts are finalized, it seems.
Seems like it should be possible to create an MRP right now, if you could?
To build Godot with debug symbols you need to pass
dev_build=yes
ordebug_symbols=yes
to the compilation command.