Crash on launch after use "check" function

Hello.

I have a problem after use “check” function in c++.

First I make an actor component which c++ class and add a line in constructor

check( GetOwner()->IsA<TemplatePlayer>() );

And compile in editor, it crashed;;;;
After I try open project, but always crashed T^T…

I deleted that class in file explorer, but not fixed.

How can I do???

===================crash info=========================
MachineId:A724F50E4894E60AD879108BD150D767
EpicAccountId:d22eb952fb64447dbfe539d10c5c3267

Access violation - code c0000005 (first/second chance not available)

UE4Editor_SampleMySurvior_3280!UStateCreature::UStateCreature() [d:\working\programming\unreal\samplemysurvior\source\samplemysurvior\creature\statecreature.cpp:15]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\coreuobject\private\uobject\class.cpp:2763]
UE4Editor_CoreUObject!UObjectLoadAllCompiledInDefaultProperties() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:724]
UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:818]
UE4Editor_CoreUObject!TBaseStaticDelegateInstance::ExecuteIfSafe() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:1021]
UE4Editor_Core!TBaseMulticastDelegate::Broadcast() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\public\delegates\delegatesignatureimpl_variadics.inl:921]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\core\private\modules\modulemanager.cpp:427]
UE4Editor_Projects!FModuleDescriptor::LoadModulesForPhase() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\projects\private\moduledescriptor.cpp:398]
UE4Editor_Projects!FProjectManager::LoadModulesForProject() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\projects\private\projectmanager.cpp:53]
UE4Editor!FEngineLoop::LoadStartupModules() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\launchengineloop.cpp:2081]
UE4Editor!FEngineLoop::PreInit() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\launchengineloop.cpp:1544]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\launch.cpp:110]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++ue4+release-4.11\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

====================================================================
Self makeshift fix;;

  1. Open the solution on visual studio.
  2. Commet a line which is generated error(or delete a line)
  3. Open project on UE4 Editor.
  4. Open well :slight_smile:

But I think that is not right way. Anyone know why “check” function generates error??

Because that how check works, it assertion test and if it’s fails (argument is false) it crashes engine with asset error in logs (Saved/Logs in project directory). Assertion in programming is a theoretically concept which prevents hard to debug unexpected crashes or instabilities by checking if conditions that your code assumes are meet, if they arrent they made lead to crash or some other unexpected behaviors… since you code don’t expect that condition you defined in check is not met. In other words it better to crash engine now then lead it to insensibility that it’s hard to debug. Engine use assertion a lot, this way it easier to debug crashes as you getting hint in logs what went wrong

This is for situations that may happen but you assume it won’t happen as you assume rest of the code use your function properly, if you can and it allowed by you code concept generly it better to prepare code for specific state.

Also you might be unaware of that but constructors are executed on start of the engine when CDOs (Class Default Objects) are made, that why you getting this crash on start not when class is actully used. It’s also reason why constructors in UObjects should not contain any active code, only defaults set, as it will effect CDO which may mess up things and not to mention on that stage not only object it self is not fully init but also engine it self, i suspect you actually getting crash from GetOwner() then check.

For init code you should use event function override in actors PostInitializeComponents() (is called on both editor when you place actor on level as well as play mode) or BeginPlay() (only play mode) and in UObject PostInitProperties().

I was using ‘check’ in BeginPlay to test if a data table was loaded and it would fail on launch, but when I relaunched it, the check did not fail. Also, it never failed while testing in the editor. I decided to replace ‘check’ with a call to IsValid, but it did not fail and the data table did not load.