[Orxonox-commit 5864] r10524 - code/branches/core7/src/libraries/core
landauf at orxonox.net
landauf at orxonox.net
Thu Jun 4 22:32:53 CEST 2015
Author: landauf
Date: 2015-06-04 22:32:52 +0200 (Thu, 04 Jun 2015)
New Revision: 10524
Modified:
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/Core.h
code/branches/core7/src/libraries/core/Game.cc
code/branches/core7/src/libraries/core/Game.h
Log:
unload graphics when the game exits
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-05-31 12:46:32 UTC (rev 10523)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-06-04 20:32:52 UTC (rev 10524)
@@ -308,7 +308,7 @@
orxout(internal_info) << "loading graphics in Core" << endl;
// Any exception should trigger this, even in upgradeToGraphics (see its remarks)
- Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
+ Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics, true);
// Upgrade OGRE to receive a render window
try
@@ -356,7 +356,7 @@
orxout(internal_info) << "finished loading graphics in Core" << endl;
}
- void Core::unloadGraphics()
+ void Core::unloadGraphics(bool loadGraphicsManagerWithoutRenderer)
{
orxout(internal_info) << "unloading graphics in Core" << endl;
@@ -367,7 +367,10 @@
// Load Ogre::Root again, but without the render system
try
- { this->graphicsManager_ = new GraphicsManager(false); }
+ {
+ if (loadGraphicsManagerWithoutRenderer)
+ this->graphicsManager_ = new GraphicsManager(false);
+ }
catch (...)
{
orxout(user_error) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << endl
Modified: code/branches/core7/src/libraries/core/Core.h
===================================================================
--- code/branches/core7/src/libraries/core/Core.h 2015-05-31 12:46:32 UTC (rev 10523)
+++ code/branches/core7/src/libraries/core/Core.h 2015-06-04 20:32:52 UTC (rev 10524)
@@ -79,7 +79,7 @@
void postUpdate(const Clock& time);
void loadGraphics();
- void unloadGraphics();
+ void unloadGraphics(bool loadGraphicsManagerWithoutRenderer = true);
void loadModules();
void unloadModules();
Modified: code/branches/core7/src/libraries/core/Game.cc
===================================================================
--- code/branches/core7/src/libraries/core/Game.cc 2015-05-31 12:46:32 UTC (rev 10523)
+++ code/branches/core7/src/libraries/core/Game.cc 2015-06-04 20:32:52 UTC (rev 10524)
@@ -517,7 +517,7 @@
orxout(internal_info) << "loading graphics in Game" << endl;
core_->loadGraphics();
- Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
+ Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true);
// Construct all the GameStates that require graphics
for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
@@ -538,7 +538,7 @@
}
}
- void Game::unloadGraphics()
+ void Game::unloadGraphics(bool loadGraphicsManagerWithoutRenderer)
{
if (GameMode::showsGraphics())
{
@@ -554,7 +554,7 @@
++it;
}
- core_->unloadGraphics();
+ core_->unloadGraphics(loadGraphicsManagerWithoutRenderer);
}
}
@@ -575,7 +575,7 @@
LOKI_ON_BLOCK_EXIT_OBJ(*this, &Game::resetChangingState); (void)LOKI_ANONYMOUS_VARIABLE(scopeGuard);
// If state requires graphics, load it
- Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
+ Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true);
if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics())
this->loadGraphics();
else
@@ -611,14 +611,11 @@
orxout(internal_warning) << "There might be potential resource leaks involved! To avoid this, improve exception-safety." << endl;
}
// Check if graphics is still required
- if (!bAbort_)
- {
- bool graphicsRequired = false;
- for (unsigned i = 0; i < loadedStates_.size(); ++i)
- graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
- if (!graphicsRequired)
- this->unloadGraphics();
- }
+ bool graphicsRequired = false;
+ for (unsigned i = 0; i < loadedStates_.size(); ++i)
+ graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
+ if (!graphicsRequired)
+ this->unloadGraphics(!this->bAbort_); // if abort is false, that means the game is still running while unloading graphics. in this case we load a graphics manager without renderer (to keep all necessary ogre instances alive)
this->bChangingState_ = false;
}
Modified: code/branches/core7/src/libraries/core/Game.h
===================================================================
--- code/branches/core7/src/libraries/core/Game.h 2015-05-31 12:46:32 UTC (rev 10523)
+++ code/branches/core7/src/libraries/core/Game.h 2015-06-04 20:32:52 UTC (rev 10524)
@@ -147,7 +147,7 @@
Game(Game&); // don't mess with singletons
void loadGraphics();
- void unloadGraphics();
+ void unloadGraphics(bool loadGraphicsManagerWithoutRenderer = true);
void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode);
bool checkState(const std::string& name) const;
More information about the Orxonox-commit
mailing list