Fixes a bug that caused unloading a world to sometimes crash the game.