Prevent game play c++ bugs crashing the editor

Hey guys

I am new to developing in unreal but am a fairly experienced programmer so pretty comfortable with C++ even though I am a bit new at it. One thing I have found is when I have a bug in my C++ code it will crash both my game and the editor when debugging. I was wondering if that is expected behaviour or am I do I not have something setup correctly? Is there some way to catch all the exceptions or errors raised and log them to the output instead of crashing the editor (which is rather frustrating).


Take a look here:

C++ bugs crashing your editor is expected behavior. As for preventing it from crashing the editor, I don’t believe that option exists.

When you build your project in “Development Editor” or “Debug Editor” mode you basically build a game with the editor around it. So if you run the game in the editor, no new process is started (except if you run it as “Standalone Game”). Most exceptions lead to a state where the CPU is not able to continue in a reasonable way (illegal memory access usually). Therefore the process can’t continue and your editor including the game will crash.

To prevent this you have to handle possible errors before they happen. So if you access a pointer test if it is valid before. If you expect any value to be in a certain range test for it (avoid divide by zero through testing the value).

To help with testing you can use the assertions in the documentation. See the link BrUnO XaVIeR posted.

Thanks for the help guys. I was aware of the assertions but was hoping there was a way to handle the errors if I have forgotten an assertion.

Doesn’t really matter though, I will just have to be vigilant with my assertions!

We have our own Assert Library that overrides the Engines’ Check and CheckF macros. Unfortunately it’s not my code so i can’t share, but I will harass the guy who wrote it, it’s literally the most useful thing we have.

The Engine has other assertion macros like ‘Ensure’ for example, some of them don’t force the editor to crash.

Tropid mentioned this but it may not have been expressed loudly enough. Running as Standalone Game will allow you to survive a crash. It will crash the standalone window but the editor remains unscathed.