VaRest
VaRest copied to clipboard
Crash when closing game with running request
Problem description
Especially noticeable in play-in-editor mode, UE crashes when the game/PIE is exited while a VaRest request is still running. The crash occurs in the response processing callback. More precisely here. When entering the if (ContinueAction)
block, the pointer value of ContinueAction
is copied into K
, ContinueAction
is set to nullptr
and FVaRestLatentAction
's Call
method is invoked on the copied pointer value in K
.
Impact: This shouldn't be too problematic for production releases as a crash during game exit often isn't noticeable. During development, this is productivity-killing.
Error analysis
I guess during game end, the garbage collector marks ContinueActions
's underlying FVaRestLatentAction
object as "pending delete". When setting ContinueAction
to nullptr
, the underlying FVaRestLatentAction
object is destroyed as K
is not a member variable but merely a scoped variable, nor is it a shared pointer. Therefore, K
is a dangling pointer when reaching the final Call
method call (so far my theory goes).
Solution attempt
I tried replacing the raw C++ pointer to FVaRestLatentAction
with TSharedPtr
and added a ContinueAction.IsValid()
check in the surrounding if-block, but this led to memory allocation exceptions during normal operation. As I'm no UE expert, my knowledge about memory management in UE is limited and I cannot give any comprehensive insights into why.
Final question
Any clue on how to fix this?
Error log:
Fatal error!
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x000005c468229fd0
0x000005c468229fd0 UnknownFunction []
0x00007ffa837b44aa UnrealEditor-VaRest.dll!UVaRestRequestJSON::OnProcessRequestComplete() [<redacted>\build\U5M-Marketplace\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\VaRest\Source\VaRest\Private\VaRestRequestJSON.cpp:581]
0x00007ffa837ae1c6 UnrealEditor-VaRest.dll!TBaseUObjectMethodDelegateInstance<0,UVaRestRequestJSON,void __cdecl(TSharedPtr<IHttpRequest,1>,TSharedPtr<IHttpResponse,1>,bool),FDefaultDelegateUserPolicy>::ExecuteIfSafe() [<redacted>\5.3.0-27405482+++UE5+Release-5.3\Working\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:665]
0x00007ffaac0e77cf UnrealEditor-HTTP.dll!UnknownFunction []
0x00007ffaac1026d9 UnrealEditor-HTTP.dll!UnknownFunction []
0x00007ffaac1327ff UnrealEditor-HTTP.dll!UnknownFunction []
0x00007ffab7c95115 UnrealEditor-Core.dll!UnknownFunction []
0x00007ffab7c96870 UnrealEditor-Core.dll!UnknownFunction []
0x00007ffab7cb541b UnrealEditor-Core.dll!UnknownFunction []
0x00007ffab7c81778 UnrealEditor-Core.dll!UnknownFunction []
0x00007ffab7c9508e UnrealEditor-Core.dll!UnknownFunction []
0x00007ffab7c96870 UnrealEditor-Core.dll!UnknownFunction []
0x00007ffab7cb541b UnrealEditor-Core.dll!UnknownFunction []
0x00007ff66497cea9 UnrealEditor.exe!UnknownFunction []
0x00007ff66499d28c UnrealEditor.exe!UnknownFunction []
0x00007ff66499d37a UnrealEditor.exe!UnknownFunction []
0x00007ff6649a0854 UnrealEditor.exe!UnknownFunction []
0x00007ff6649b6984 UnrealEditor.exe!UnknownFunction []
0x00007ff6649b9d7a UnrealEditor.exe!UnknownFunction []
0x00007ffb7935257d KERNEL32.DLL!UnknownFunction []
Crash in runnable thread StallDetectorThread