| | 160 | // This code has been moved down, see there for details. |
| | 161 | // if (m_GameDLL) |
| | 162 | // { |
| | 163 | // FreeLibrary(m_GameDLL); |
| | 164 | // m_GameDLL=NULL; |
| | 165 | // } |
| | 166 | |
| | 167 | // When the game has been unloaded, no collision models must be left in the collision model manager. |
| | 168 | wxASSERT(cf::ClipSys::CollModelMan->GetUniqueCMCount()==0); |
| | 169 | |
| | 170 | |
| | 171 | // Release the GuiManager (*before* the renderer). |
| | 172 | if (cf::GuiSys::GuiMan) |
| | 173 | { |
| | 174 | delete cf::GuiSys::GuiMan; |
| | 175 | cf::GuiSys::GuiMan=NULL; |
| | 176 | } |
| | 177 | |
| | 178 | |
| | 179 | // Release the Cafu Sound System. |
| | 180 | if (SoundSystem) |
| | 181 | { |
| | 182 | SoundSystem->Release(); |
| | 183 | SoundSystem=NULL; |
| | 184 | } |
| | 185 | |
| | 186 | if (m_SoundSysDLL) |
| | 187 | { |
| | 188 | FreeLibrary(m_SoundSysDLL); |
| | 189 | m_SoundSysDLL=NULL; |
| | 190 | } |
| | 191 | |
| | 192 | |
| | 193 | // Release the GUI resources. |
| | 194 | if (m_GuiResources) |
| | 195 | { |
| | 196 | delete m_GuiResources; |
| | 197 | m_GuiResources=NULL; |
| | 198 | } |
| | 199 | |
| | 200 | |
| | 201 | // Release the model manager. |
| | 202 | if (m_ModelManager) |
| | 203 | { |
| | 204 | delete m_ModelManager; |
| | 205 | m_ModelManager=NULL; |
| | 206 | } |
| | 207 | |
| | 208 | |
| | 209 | // Release the Cafu Material System. |
| | 210 | if (MatSys::TextureMapManager) |
| | 211 | { |
| | 212 | // MatSys::TextureMapManager->FreeTextureMap(m_WhiteTexture); |
| | 213 | MatSys::TextureMapManager=NULL; |
| | 214 | } |
| | 215 | |
| | 216 | if (MatSys::Renderer) |
| | 217 | { |
| | 218 | MatSys::Renderer->Release(); |
| | 219 | MatSys::Renderer=NULL; |
| | 220 | } |
| | 221 | |
| | 222 | if (m_RendererDLL) |
| | 223 | { |
| | 224 | FreeLibrary(m_RendererDLL); |
| | 225 | m_RendererDLL=NULL; |
| | 226 | } |
| | 227 | |
| | 228 | // This code used to be further up, but under Windows at r423, the following problem exists: |
| | 229 | // Class CafuModelT is derived from class ModelT, and thus has a virtual destructor. |
| | 230 | // When we call ModelManagerT::GetModel() in the game DLL, everything works all right, |
| | 231 | // but the code linked to the game DLL is used to create the new model, which causes |
| | 232 | // the vtable of the newly created model to point to the destructor code in the game DLL. |
| | 233 | // When the call FreeLibrary(m_GameDLL); before the destructors of the models in the |
| | 234 | // m_ModelManager are run, we essentially remove the code that the virtual destructors |
| | 235 | // are pointing to, causing access violation. |
| | 236 | // Moving the call to FreeLibrary() below the "delete m_ModelManager;" fixes the problem. |
| | 237 | // |
| | 238 | // Also see this report of someone else experiencing the same problem: |
| | 239 | // http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/dacc7dbd-2775-4e86-a429-8dd32fae0e33 |
| 164 | | } |
| 165 | | |
| 166 | | // When the game has been unloaded, no collision models must be left in the collision model manager. |
| 167 | | wxASSERT(cf::ClipSys::CollModelMan->GetUniqueCMCount()==0); |
| 168 | | |
| 169 | | |
| 170 | | // Release the GuiManager (*before* the renderer). |
| 171 | | if (cf::GuiSys::GuiMan) |
| 172 | | { |
| 173 | | delete cf::GuiSys::GuiMan; |
| 174 | | cf::GuiSys::GuiMan=NULL; |
| 175 | | } |
| 176 | | |
| 177 | | |
| 178 | | // Release the Cafu Sound System. |
| 179 | | if (SoundSystem) |
| 180 | | { |
| 181 | | SoundSystem->Release(); |
| 182 | | SoundSystem=NULL; |
| 183 | | } |
| 184 | | |
| 185 | | if (m_SoundSysDLL) |
| 186 | | { |
| 187 | | FreeLibrary(m_SoundSysDLL); |
| 188 | | m_SoundSysDLL=NULL; |
| 189 | | } |
| 190 | | |
| 191 | | |
| 192 | | // Release the GUI resources. |
| 193 | | if (m_GuiResources) |
| 194 | | { |
| 195 | | delete m_GuiResources; |
| 196 | | m_GuiResources=NULL; |
| 197 | | } |
| 198 | | |
| 199 | | |
| 200 | | // Release the model manager. |
| 201 | | if (m_ModelManager) |
| 202 | | { |
| 203 | | delete m_ModelManager; |
| 204 | | m_ModelManager=NULL; |
| 205 | | } |
| 206 | | |
| 207 | | |
| 208 | | // Release the Cafu Material System. |
| 209 | | if (MatSys::TextureMapManager) |
| 210 | | { |
| 211 | | // MatSys::TextureMapManager->FreeTextureMap(m_WhiteTexture); |
| 212 | | MatSys::TextureMapManager=NULL; |
| 213 | | } |
| 214 | | |
| 215 | | if (MatSys::Renderer) |
| 216 | | { |
| 217 | | MatSys::Renderer->Release(); |
| 218 | | MatSys::Renderer=NULL; |
| 219 | | } |
| 220 | | |
| 221 | | if (m_RendererDLL) |
| 222 | | { |
| 223 | | FreeLibrary(m_RendererDLL); |
| 224 | | m_RendererDLL=NULL; |