Permalink
Browse files

Ensure 'gource' never points to a deleted reference.

  • Loading branch information...
1 parent 5328b8c commit 2f491448a3d44a15a4943678123340ea819590b5 @acaudwell committed Apr 12, 2012
Showing with 27 additions and 15 deletions.
  1. +20 −12 src/gource_shell.cpp
  2. +3 −1 src/gource_shell.h
  3. +4 −2 src/main.cpp
View
@@ -17,6 +17,8 @@
#include "gource_shell.h"
+GourceShell* gGourceShell = 0;
+
// GourceShell
GourceShell::GourceShell(ConfFile* conf, FrameExporter* exporter) {
@@ -141,22 +143,25 @@ void GourceShell::mouseClick(SDL_MouseButtonEvent *e) {
}
void GourceShell::quit() {
- if(gource!=0) gource->quit();
- shutdown=true;
+ if(gource!=0) gource->quit();
+ shutdown=true;
}
Gource* GourceShell::getNext() {
if(gource!=0) {
- delete gource;
- gource = 0;
-
transition_interval = 1.0f;
}
- if(shutdown) return 0;
+ if(shutdown || gource_settings == conf->getSections("gource")->end()) {
+
+ // if we are done, delete gource and replace it with nothing
+ if(gource != 0) {
+ Gource* gource_tmp = gource;
+ gource = 0;
+ delete gource_tmp;
+ }
- if(gource_settings == conf->getSections("gource")->end()) {
return 0;
}
@@ -187,10 +192,14 @@ Gource* GourceShell::getNext() {
}
}
- Gource* gource = new Gource(exporter);
-
+ // replace gource
+
+ Gource* gource_tmp = gource;
+ gource = new Gource(exporter);
+ delete gource_tmp;
+
next = false;
-
+
return gource;
}
@@ -227,9 +236,8 @@ void GourceShell::blendLastFrame(float dt) {
void GourceShell::update(float t, float dt) {
if(gource == 0 || gource->isFinished()) {
- gource = getNext();
+ if(!getNext()) appFinished=true;
- if(gource==0) appFinished=true;
return;
}
View
@@ -49,7 +49,7 @@ class GourceShell : public SDLApp {
void toggleFullscreen();
void quit();
-
+
void keyPress(SDL_KeyboardEvent *e);
void mouseMove(SDL_MouseMotionEvent *e);
void mouseClick(SDL_MouseButtonEvent *e);
@@ -59,3 +59,5 @@ class GourceShell : public SDLApp {
};
#endif
+
+extern GourceShell* gGourceShell;
View
@@ -126,7 +126,7 @@ int main(int argc, char *argv[]) {
if(gGourceSettings.resizable && gGourceSettings.output_ppm_filename.empty()) {
display.enableResize(true);
}
-
+
try {
display.init("Gource", gGourceSettings.display_width, gGourceSettings.display_height, gGourceSettings.fullscreen);
@@ -168,7 +168,7 @@ int main(int argc, char *argv[]) {
GourceShell* gourcesh = 0;
try {
- gourcesh = new GourceShell(&conf, exporter);
+ gourcesh = gGourceShell = new GourceShell(&conf, exporter);
gourcesh->run();
} catch(ResourceException& exception) {
@@ -186,6 +186,8 @@ int main(int argc, char *argv[]) {
SDLAppQuit(exception.what());
}
}
+
+ gGourceShell = 0;
if(gourcesh != 0) delete gourcesh;
if(exporter != 0) delete exporter;

0 comments on commit 2f49144

Please sign in to comment.