GameAnalytics / GA-SDK-CPP

Repository for GameAnalytics C++ SDK.
MIT License
20 stars 16 forks source link

UnrealEngine4 GameAnalytics plugin prevents UE4Editor shutdown #66

Closed BonAppetit34 closed 6 years ago

BonAppetit34 commented 6 years ago

Unreal Version: 4.19.2, 4.20.2 GameAnalytics Plugin Version: 2.6.28, 3.0.1
OS/Toolchain: Windows 10, VS 2017 (v15.8.1), Win 10 SDK

Repro:

  1. Start UE4 Editor (create new "First Person" project) and enable GameAnalytics plugin
  2. Restart UE4 Editor
  3. Close UE4 Editor (File->Exit or Close Window)

Repro Rate: 10 out of 10

Observed Behavior: Editor window closes, but process stays running in the Windows Task Manager. When attaching a debugger the call stack shows the GA Analytics plugin waiting (see call stack below).

Expected Behavior: Editor process exits properly without hanging.

Callstack:

ntdll.dll!NtWaitForAlertByThreadId()    Unknown
ntdll.dll!RtlSleepConditionVariableSRW()    Unknown
KernelBase.dll!SleepConditionVariableSRW()  Unknown
msvcp140.dll!__crtSleepConditionVariableSRW(_RTL_CONDITION_VARIABLE * pCond, _RTL_SRWLOCK * pLock, unsigned long dwMs, unsigned long flags) Line 659    C++
[Inline Frame] msvcp140.dll!Concurrency::details::stl_condition_variable_win7::wait_for(Concurrency::details::stl_critical_section_interface *) Line 216    C++
msvcp140.dll!Concurrency::details::stl_condition_variable_win7::wait(Concurrency::details::stl_critical_section_interface * lock) Line 210  C++
msvcp140.dll!do_wait(_Cnd_internal_imp_t * cond=0x00000248f0b89238, _Mtx_internal_imp_t * mtx=0x00000248f0b891e8, const xtime * target=0x0000000000000000) Line 77  C++
UE4Editor-GameAnalytics-Win64-Debug.dll!std::_Associated_state<void *>::_Wait(void) C++
UE4Editor-GameAnalytics-Win64-Debug.dll!std::_Task_async_state<void *,0>::~_Task_async_state<void *,0>(void)    C++
UE4Editor-GameAnalytics-Win64-Debug.dll!std::_Task_async_state<void *,0>::`vector deleting destructor'(unsigned int)    C++
UE4Editor-GameAnalytics-Win64-Debug.dll!gameanalytics::threading::GAThreading::State::~State(void)  C++
UE4Editor-GameAnalytics-Win64-Debug.dll!`GASingleton<class gameanalytics::store::GAStore>::getInstanceHolder(void)'::`2'::`dynamic atexit destructor for 'instance_''(void) C++
ucrtbase.dll!<lambda>(void)()   Unknown
ucrtbase.dll!__crt_seh_guarded_call<int>::operator()<<lambda_7777bce6b2f8c936911f934f8298dc43>,<lambda>(void) & __ptr64,<lambda_3883c3dff614d5e0c5f61bb1ac94921c> >()   Unknown
ucrtbase.dll!_execute_onexit_table()    Unknown
UE4Editor-GameAnalytics-Win64-Debug.dll!dllmain_crt_process_detach(const bool is_terminating=true) Line 107 C++
UE4Editor-GameAnalytics-Win64-Debug.dll!dllmain_dispatch(HINSTANCE__ * const instance=0x00007ff8b35f0000, const unsigned long reason=0, void * const reserved=0x0000000000000001) Line 211  C++
ntdll.dll!LdrpCallInitRoutine() Unknown
ntdll.dll!LdrShutdownProcess()  Unknown
ntdll.dll!RtlExitUserProcess()  Unknown
kernel32.dll!ExitProcessImplementation()    Unknown
mscoreei.dll!RuntimeDesc::ShutdownAllActiveRuntimes(unsigned int,class RuntimeDesc *,enum RuntimeDesc::ShutdownCompatMode)  Unknown
mscoree.dll!ShellShim_CorExitProcess()  Unknown
ucrtbase.dll!try_cor_exit_process() Unknown
ucrtbase.dll!exit_or_terminate_process()    Unknown
ucrtbase.dll!common_exit()  Unknown
UE4Editor-Win64-Debug.exe!__scrt_common_main_seh() Line 290 C++
kernel32.dll!BaseThreadInitThunk()  Unknown
ntdll.dll!RtlUserThreadStart()  Unknown

Additional Notes: Tried to recompile GameAnalytics C++ SDK (GA-CPP_SDK v2.0.1) with VC++ v15.8.1 to ensure it is not the following VC++ standard library issue, but same behavior as described above: https://developercommunity.visualstudio.com/content/problem/257344/stdasync-can-crash-or-deadlock.html

the1schwartz commented 6 years ago

Thanks for reporting this. I have made a fix which should fix this issue in the latest version. Please let me know if the issue still exists after the update.

BonAppetit34 commented 6 years ago

Thank you for the quick response. Unfortunately I observe the same behavior as described above with GS-SDK-CPP v2.0.2 (I replaced GameAnalytics.lib in UE4 GameAnalytics plugin v3.0.1)

I also tried, without success, the fix from https://github.com/leyyin/GA-SDK-CPP/commit/f33f220cf9dfa68edca2a19a808480d5ad0de656

I don't have any experience with std::async(), but was wondering when seeing a mutex in your implementation and reading

[...]but don't even think of using async() to launch tasks that do I/O, manipulates mutexes, or in other ways interact with other tasks.

here: http://www.stroustrup.com/C++11FAQ.html#std-async

BonAppetit34 commented 6 years ago

Issue still occurs with UE 4.20.2 and GA plugin 3.0.2

the1schwartz commented 6 years ago

Thanks, I am looking into it.

the1schwartz commented 6 years ago

I have just released a new version of the Unreal SDK (3.0.3), you need to download the latest version of the Unreal SDK (https://github.com/GameAnalytics/GA-SDK-UNREAL) as well there is also some fixed in the Unreal files as well. Please let me know if this fixes the issue and so I know if I can close this issue or not.

BonAppetit34 commented 6 years ago

Fix verified. Described issue can not be observed in GA plugin v3.0.3 anymore. Thanks again for the quick response.

the1schwartz commented 6 years ago

Great thanks again for reporting this.