I don't know too much about how the engine works internally, so I always use a level initialization and level closing function to set up and destroy things properly to avoid such a crash... and keeping loop quantity low is also a handy solution to clearly see through what happens.