I currently have a class, SDLSubSystem, that inherits from two interfaces: IWindowSystem and ITimerSystem. In my game engine, I have a pointer to a timer system and a pointer to a window system. When SDL is configured, both pointers will end up pointing to SDLSubSystem:
if (m_config.compare("SDL") == 0) { SDLSubSystem *sdlSystem = new SDLSubSystem(); sdlSystem->init(); m_winSystem = sdlSystem;; m_timerSystem = sdlSystem;}
The problem comes when the user quits the window and the engine is shutting down. Before I am able to delete either of the pointers, the other one needs to be set to null:
if (m_config.compare("SDL")) { m_timerSystem = NULL; delete m_winSystem;}
My problem is... this solution is horrible because it could escalate and cleanup isn't as nice as I'd like it to be. Here's what I've researched:
- I've read up on the Enginuity Engine's method for memory management but I also read some articles on the problems of reference counting with pointers.
- I also read up on auto_ptr and heard that it will be deprecated soon, so I don't want to use it.
- I can't seem to get the new standard, unique_ptr, to work on Visual Studio 2008 (I assume that's because it's not a standard yet...)
I'd appreciate any help/insight you may have. Thank you :)