Scene.ThreadManager and Dispose
Posted: Sat Sep 28, 2013 5:18 am
Hi Norbo,
I have recently started retaining a ThreadTaskManager that lives through the lifespan of the application. There are multiple Space instances that are created & disposed as the game runs, primarily to ensure there are no unintended leaks between parts of the game that transition between completely different areas (think switching maps in Team Fortress or any other shooter, it's a completely set of entities when it switches). Previously, I created a ThreadTaskManager for each Space but in the interest of using the ThreadTaskManager more widely in my game, I keep one around that I use for tasks outside the scope of physics. Anyway, the Space constructors take an IThreadManager as a parameter, but the Space Dispose will always dispose the provided IThreadManager. Setting Space.ThreadManager to null before Space.Dispose doesn't work either, as the Space.Dispose assumes a valid ThreadManager to dispose.
I made my own local changes to just clear the Space.ThreadManager and check for null in Space.Dispose, but it seems to me that since the Space is provided the ThreadManager as a ctor parameter it shouldn't be taking responsibility for disposing it.
I just wanted to point that out for something for you to consider.
Incidentally, I create & destroy the Space instances mainly because it seems likely a better choice than manually removing every object in the Space and hoping something didn't get missed. Is this perhaps overkill? Should just removing all objects in the Space sufficiently reset it or will there be lingering events or something else I don't know about yet that might cause referenced object leaks? When switching game modes, I pretty much just want to dump the entire scene contents which is why I currently just dispose the whole thing. It would be nice if there was a safe "Reset" method that would reliably reset the Space to an empty state.
Thanks,
I have recently started retaining a ThreadTaskManager that lives through the lifespan of the application. There are multiple Space instances that are created & disposed as the game runs, primarily to ensure there are no unintended leaks between parts of the game that transition between completely different areas (think switching maps in Team Fortress or any other shooter, it's a completely set of entities when it switches). Previously, I created a ThreadTaskManager for each Space but in the interest of using the ThreadTaskManager more widely in my game, I keep one around that I use for tasks outside the scope of physics. Anyway, the Space constructors take an IThreadManager as a parameter, but the Space Dispose will always dispose the provided IThreadManager. Setting Space.ThreadManager to null before Space.Dispose doesn't work either, as the Space.Dispose assumes a valid ThreadManager to dispose.
I made my own local changes to just clear the Space.ThreadManager and check for null in Space.Dispose, but it seems to me that since the Space is provided the ThreadManager as a ctor parameter it shouldn't be taking responsibility for disposing it.
I just wanted to point that out for something for you to consider.
Incidentally, I create & destroy the Space instances mainly because it seems likely a better choice than manually removing every object in the Space and hoping something didn't get missed. Is this perhaps overkill? Should just removing all objects in the Space sufficiently reset it or will there be lingering events or something else I don't know about yet that might cause referenced object leaks? When switching game modes, I pretty much just want to dump the entire scene contents which is why I currently just dispose the whole thing. It would be nice if there was a safe "Reset" method that would reliably reset the Space to an empty state.
Thanks,