How can I debug C++ crashing the editor?

Hello I am experiencing an editor crash from one line of code inside of a constructor of another class.

Specifically…


ATileObject* tObject = GetWorld()->SpawnActor<ATileObject>(FVector(0.f, 0.f, 0.f), FRotator(0, 0, 0));

If I comment out this line the editor no longer crashes. It doesn’t crash on begin play, but on DLL load (I would expect it to crash on run, because the object that has the above line of code is not created until run time)

Anyway I tried compiling for DebugGame Editor, renaming the resulting DLL so the editor would load it, but that still crashes.

I have sent a crash report once, but for reference here’s the thing:

Using editor 4.6.1. Also don’t know why it doesn’t show my EpicAccountId there.

I’m not even sure if this is something I can debug myself, or if it is something Epic’s side.

Correct me if I’m wrong, but can you actually call Spawn Actor from inside a constructor?

Are you doing anything network/MP related at all?

You can try with DebugEditor build option to ensure you have symbols for all the editor code

Its not save to use spawn actor on the world inside a constructor.

I’m not sure if I can do it inside the constructor. I know for sure though you can create a text object in it though, as that’s what the puzzle game template does and you can see the text in the editor preview. Nothing network/multiplayer.

Already tried that as explained in the OP. Does not provide any additional information from what I can tell.

OK thanks for info. As with what TheJamsh has said, I am able to put the code in BeginPlay which is good enough for me.

I’ve gotten the same types of errors. Every time I put initialization code for an instanced object inside of a constructor, it seems to crash the editor. I’ve learned not to do this anymore. Why does the editor crash? Because when you load the editor, it actually calls the constructor for your objects during the editor load. If you have things like “GetWorld()” in there, the world doesn’t exist yet and returns NULL. So, you’re trying to dereference a null value in your constructor and that causes the crash in the editor.

What you’re trying to do is get the world during game play, not in the editor. There are a few options:

Not recommended:
Keep the code in the constructor, but check for null values on your world before dereferencing it.

Recommended:
Create a separate initialization method in your class and call it in your blueprint’s “OnBeginPlay” event. Use this to initialize the object with any game play specific settings.

In the OP you say you tried DebugGame. I said to try DebugEditor :slight_smile:

BTW. My advice is for Debugging the editor itself. Four your particular concern, as others said, you should not use GetWorld() inside a constructor. That is because in CDO construction there is not world at all so dereferencing it will crash.

As far as the crash goes, don’t acces GetWorld() or try to spawn stuff in the constructor in general, it’s not safe. Use PostInitializeComponents() or BeginPlay() instead.

As far as debugging goes. Just make sure you pick a debuggable build config in Visual Studio. In addition to that add all the engine source files as dependencies (or build the whole engine yourself) so the debugger has access to the .cpp files of the engine.

This compiles the entire engine in Debug, which is a waste of time and performance in this case since the crash occurs in game code.

DebugGame is the best compromise for debugging the game, however the project file generation does not automatically put the -debug command line switch to have the editor use DebugGame libraries. Directions for this are here.