- properly cleanup models in g3dviewer to fix shutdown bug

This commit is contained in:
SoftCoder 2014-12-23 20:39:03 -08:00
parent 7f0b199929
commit b1455c0e33
4 changed files with 22 additions and 11 deletions

@ -1 +1 @@
Subproject commit b1c0f0cc18cdd2311b581b44e7ae161317438c93 Subproject commit 5517be4d27fd05ff4379b23c84fe8f6aed183f0b

View File

@ -299,6 +299,9 @@ MainWindow::MainWindow( std::pair<string,vector<string> > unitToLoad,
this->appPath = appPath; this->appPath = appPath;
Properties::setApplicationPath(executable_path(appPath)); Properties::setApplicationPath(executable_path(appPath));
lastanim = 0;
model= NULL;
Config &config = Config::getInstance(); Config &config = Config::getInstance();
//getGlPlatformExtensions(); //getGlPlatformExtensions();
@ -313,8 +316,6 @@ MainWindow::MainWindow( std::pair<string,vector<string> > unitToLoad,
glCanvas->SetCurrent(); glCanvas->SetCurrent();
#endif #endif
lastanim = 0;
model= NULL;
unitPath = unitToLoad; unitPath = unitToLoad;
if(modelPath != "") { if(modelPath != "") {
@ -555,8 +556,9 @@ MainWindow::~MainWindow(){
delete fileDialog; delete fileDialog;
fileDialog = NULL; fileDialog = NULL;
delete model; //delete model;
model = NULL; //model = NULL;
if(renderer) renderer->end();
delete renderer; delete renderer;
renderer = NULL; renderer = NULL;
@ -742,7 +744,6 @@ void MainWindow::onClose(wxCloseEvent &event){
particleSplashPathList.clear(); // as above particleSplashPathList.clear(); // as above
if(timer) timer->Stop(); if(timer) timer->Stop();
if(renderer) renderer->end();
unitParticleSystems.clear(); unitParticleSystems.clear();
unitParticleSystemTypes.clear(); unitParticleSystemTypes.clear();
@ -752,8 +753,9 @@ void MainWindow::onClose(wxCloseEvent &event){
splashParticleSystems.clear(); // as above splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear(); splashParticleSystemTypes.clear();
delete model; //delete model;
model = NULL; //model = NULL;
if(renderer) renderer->end();
//printf("OnClose about to END\n"); //printf("OnClose about to END\n");
//fflush(stdout); //fflush(stdout);
@ -1112,7 +1114,9 @@ void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
splashParticleSystems.clear(); // as above splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear(); splashParticleSystemTypes.clear();
delete model; //delete model;
//model = NULL;
if(model != NULL && renderer != NULL) renderer->endModel(rsGlobal, model);
model = NULL; model = NULL;
loadUnit("",""); loadUnit("","");
@ -1284,7 +1288,9 @@ void MainWindow::loadModel(string path) {
//printf("Loading model [%s] %u of " MG_SIZE_T_SPECIFIER "\n",modelPath.c_str(),idx, this->modelPathList.size()); //printf("Loading model [%s] %u of " MG_SIZE_T_SPECIFIER "\n",modelPath.c_str(),idx, this->modelPathList.size());
if(timer) timer->Stop(); if(timer) timer->Stop();
delete model; //delete model;
if(model != NULL && renderer != NULL) renderer->endModel(rsGlobal, model);
model = NULL;
model = renderer? renderer->newModel(rsGlobal, modelPath): NULL; model = renderer? renderer->newModel(rsGlobal, modelPath): NULL;
statusbarText = getModelInfo(); statusbarText = getModelInfo();
@ -1859,7 +1865,7 @@ void MainWindow::onTimer(wxTimerEvent &event) {
string MainWindow::getModelInfo() { string MainWindow::getModelInfo() {
string str; string str;
if(model!=NULL){ if(model != NULL) {
str+= "Meshes: "+intToStr(model->getMeshCount()); str+= "Meshes: "+intToStr(model->getMeshCount());
str+= ", Vertices: "+intToStr(model->getVertexCount()); str+= ", Vertices: "+intToStr(model->getVertexCount());
str+= ", Triangles: "+intToStr(model->getTriangleCount()); str+= ", Triangles: "+intToStr(model->getTriangleCount());

View File

@ -200,6 +200,10 @@ Model * Renderer::newModel(ResourceScope rs,const string &path,bool deletePixMap
return modelManager->newModel(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); return modelManager->newModel(path,deletePixMapAfterLoad,loadedFileList,sourceLoader);
} }
void Renderer::endModel(ResourceScope rs,Model *model) {
modelManager->endModel(model);
}
void Renderer::init() { void Renderer::init() {
assertGl(); assertGl();

View File

@ -147,6 +147,7 @@ public:
Texture2D * getNewTexture2D(); Texture2D * getNewTexture2D();
Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL); Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL);
void endModel(ResourceScope rs,Model *model);
Texture2D *newTexture2D(ResourceScope rs) { return getNewTexture2D(); } Texture2D *newTexture2D(ResourceScope rs) { return getNewTexture2D(); }
void initTextureManager(); void initTextureManager();