I tried "last_error" already, but the engine crashes once it reaches the wait(1), so the last_error block is never reached.

Removing entities from the level one by one doesn't help as the crsah disappears once I remove or add an entity from the level. But I'm sure this is no fix at all as the error will just appear at another point of the game (if it is some memory issue).