what I use to avoid similar issues:
- a level close function to always stop running stuff: player, sky, camera, panels, material/shader loops (especially shade-c related ones),
- protections to avoid running anything double (by proc_status or boolean-like islooprunning variables),
- remove and NULL global pointers to engine objects. entities are auto removed very fast, but if you use some with global entity pointers they are better to be handled carefully manually
- always check whether a global e.g. entity is NULL or not before actually using it
- create and remove panels (and possibly all other engine objects) runtime to avoid linking to removed objects
- totally rewrite the full code in every 6 months grin


Free world editor for 3D Gamestudio: MapBuilder Editor