How to handle null pointers

RemzDNB
Mon, 11 Jan 2021 13:56:30 +0000
Platform & Builds

Hey guys, quite new to C++ stuff here !
I was wondering, how do you handle invalid references without crashing the whole engine ?
For example I’m loading a DataTable from my code with FObjectFinder and a hard path. I can check if the pointer is nullptr, then log something like “Missing DataTable”, but what then ? If the game keeps running, it will crash the engine, I rather want it to stop and go back to the editor, so I can read the log and correct my mistake.
What should I do ? I could exit it with a console command but it seems ugly to me. I also read about stuff like check() and assert() but I don’t understand how it works and it should also crash the editor, so that’s not what I’m looking for.
Thanks
Remz

2 posts - 1 participant