Download

Ensure() not working after first run of compilation.

I’m using ensure() to check for a valid pointer like so:

if ( !ensure(MyPointer) ) return;

After a compilation, and then using Play In Editor, the log spits out a bunch of red lines with:

LogOutputDevice: Error: === Handled ensure: ===
LogOutputDevice: Error: Ensure condition failed: MyPointer [File:C:\projects\Unreal Projects\MyProject\Source\Proj\Private\MyClass.cpp] [Line: 63]
LogOutputDevice: Error: Stack:
LogOutputDevice: Error: [Callstack] 0x000007fee96f71f6 UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [d:\build++ue4\sync\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:236]



LogOutputDevice: Error: [Callstack] 0x000000013f3a5cbd UE4Editor.exe!FEngineLoop::Tick() [d:\build++ue4\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3495]
LogOutputDevice: Error: [Callstack] 0x000000013f3b5b3c UE4Editor.exe!GuardedMain() [d:\build++ue4\sync\engine\source\runtime\launch\private\launch.cpp:166]
LogOutputDevice: Error: [Callstack] 0x000000013f3b5bba UE4Editor.exe!GuardedMainWrapper() [d:\build++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:144]
LogOutputDevice: Error: [Callstack] 0x000000013f3c3dac UE4Editor.exe!WinMain() [d:\build++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:223]
LogOutputDevice: Error: [Callstack] 0x000000013f3c5aaa UE4Editor.exe!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283]
LogOutputDevice: Error: [Callstack] 0x0000000076f2652d kernel32.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000007705c541 ntdll.dll!UnknownFunction ]

Thereafter, the ensure does not trigger any more, even after stopping and starting again in the PIE until the next compilation or restarting the Editor.

What’s going on here, and how can I fix this so that my ensure works again?

ensure() only triggers the first time until you restart the editor

Use ensureAlways()

Oh, I see. Is this in the official docs somewhere? If not, are there any performance considerations I need to be worried about when using ensure() or ensureAlway() ? Seems like the first time an ensure() fails, it locks up my computer for several seconds.

It’s usually only locking up because it’s gathering info (often it’s just visual studio locking up while it analyses variables etc.) As far as the engine is concerned it’s pretty much just doing the same as any other assertion so there’s no (measurable) cost involved. I believe ensures that fail will trigger a crash in a packaged game but I can’t remember if that’s only the check macro.

It’s not mentioned in docs - in UE4 the best documentation is the code itself. If you right-click ‘ensure’ and hit ‘Peek Definition’ it’ll take you to where ensure is defined and you can kind of pick it apart to see how it works.

I had a look and it appears that the ensure macro defines a static bool inline, that once triggered is set to true, and therefore doesn’t re-trigger afterwards. ensureAlways does no such thing :slight_smile:

I see, thanks, I’ll have a look. For now, I’ll assume that it has no performance hit, and will sprinkle it around.