I made a post on mantis, and referenced this topic (
http://taspring.clan-sy.com/mantis/view.php?id=109. As said before, and in mantis, you need not use my method of getting shutdown to be called, but it
cannot be done in the destructor.
Here's the changes:
1) make a file, Main.h (code section to follow)
2) make the modifications to Main.cpp (diff to follow)
3) find any code that has this:
Change it to this:
Code: Select all
// Other includes...
#include "System/Main.h"
// more code ...
// exit(0); is the old way :P
SpringApp::ExitCleanFromAnywhere(0);
Here's the new truct/rts/System/Main.h:
Code: Select all
#ifndef MAIN_H
#define MAIN_H
#include "StdAfx.h"
#include "Rendering/GL/myGL.h"
#include <GL/glu.h> // Header File For The GLu32 Library
#include <time.h>
#include <string>
#include <algorithm>
#include <math.h>
#include "Game/PreGame.h"
#include "Game/Game.h"
#include <float.h>
#include "Rendering/glFont.h"
#include "Rendering/Textures/TAPalette.h"
#include "Game/UI/MouseHandler.h"
#include "Platform/ConfigHandler.h"
#include "Game/UI/InfoConsole.h"
#include "Game/GameSetup.h"
#include "Game/CameraController.h"
#include "Net.h"
#include "FileSystem/ArchiveScanner.h"
#include "FileSystem/VFSHandler.h"
#include "Platform/BaseCmd.h"
#include "Game/GameVersion.h"
#include "Platform/errorhandler.h"
#include "creg/creg.h"
#include "bitops.h"
#ifndef NO_LUA
#include "Script/LuaBinder.h"
#endif
#include <SDL.h>
#include <SDL_main.h>
#include "mmgr.h"
#include "Game/UI/NewGuiDefine.h"
#ifdef NEW_GUI
#include "Game/UI/GUI/GUIcontroller.h"
#endif
#ifdef _WIN32
#include "CrashRpt.h"
#include "Platform/Win/win32.h"
#include <winreg.h>
#include <direct.h>
#include <SDL_syswm.h>
#endif
/**
* @brief Spring App
*
* Main Spring application class launched by main()
*/
class SpringApp
{
public:
SpringApp (); //!< Constructor
~SpringApp (); //!< Destructor
int Run(int argc, char *argv[]); //!< Run game loop
static void ExitCleanFromAnywhere(int retCode); //!< Exit the run game loop durring a major error
protected:
bool Initialize (); //!< Initialize app
void CheckCmdLineFile (int argc,char *argv[]); //!< Check command line for files
bool ParseCmdLine(); //!< Parse command line
void InitVFS (); //!< Initialize VFS
void CreateGameSetup (); //!< Creates GameSetup
bool InitWindow (const char* title); //!< Initializes window
void InitOpenGL (); //!< Initializes OpenGL
bool SetSDLVideoMode(); //!< Sets SDL video mode
void Shutdown (); //!< Shuts down application
int Draw (); //!< Repeated draw function
void UpdateSDLKeys (); //!< Update SDL key array
/**
* @brief command line
*
* Pointer to instance of commandline parser
*/
BaseCmd *cmdline;
/**
* @brief demofile
*
* Name of a demofile
*/
string demofile;
/**
* @brief startscript
*
* Name of a start script
*/
string startscript;
/**
* @brief screen width
*
* Game screen width
*/
int screenWidth;
/**
* @brief screen height
*
* Game screen height
*/
int screenHeight;
/**
* @brief screen freq
*
* Game screen frequency
*/
int screenFreq;
/**
* @brief active
*
* Whether game is active
*/
bool active;
/**
* @brief FSAA
*
* Level of fullscreen anti-aliasing
*/
bool FSAA;
};
#endif /* MAIN_H */
Make note of the new static void ExitClean... function below "SpringApp::Run"
Now for diff ./modified.trunk/rts/System/Main.cpp ./orig.truck/rts/System/Main.cpp
Code: Select all
7a8,42
> #include "StdAfx.h"
> #include "Rendering/GL/myGL.h"
> #include <GL/glu.h> // Header File For The GLu32 Library
> #include <time.h>
> #include <string>
> #include <algorithm>
> #include <math.h>
> #include "Game/PreGame.h"
> #include "Game/Game.h"
> #include <float.h>
> #include "Rendering/glFont.h"
> #include "Rendering/Textures/TAPalette.h"
> #include "Game/UI/MouseHandler.h"
> #include "Platform/ConfigHandler.h"
> #include "Game/UI/InfoConsole.h"
> #include "Game/GameSetup.h"
> #include "Game/CameraController.h"
> #include "Net.h"
> #include "FileSystem/ArchiveScanner.h"
> #include "FileSystem/VFSHandler.h"
> #include "Platform/BaseCmd.h"
> #include "Game/GameVersion.h"
> #include "Platform/errorhandler.h"
> #include "creg/creg.h"
> #include "bitops.h"
> #ifndef NO_LUA
> #include "Script/LuaBinder.h"
> #endif
> #include <SDL.h>
> #include <SDL_main.h>
> #include "mmgr.h"
> #include "Game/UI/NewGuiDefine.h"
> #ifdef NEW_GUI
> #include "Game/UI/GUI/GUIcontroller.h"
> #endif
9,10c44,50
< // Includes and Declairation for Springapp
< #include "Main.h"
---
> #ifdef _WIN32
> #include "CrashRpt.h"
> #include "Platform/Win/win32.h"
> #include <winreg.h>
> #include <direct.h>
> #include <SDL_syswm.h>
> #endif
57,59c97,99
< * @brief g_pMySpringAppInstance
< *
< * Easy way to get access to Springapp instance ->Shutdown() for ExitCleanFromAnywhere()
---
> * @brief Spring App
> *
> * Main Spring application class launched by main()
61c101,177
< SpringApp* g_pMySpringAppInstance = NULL;
---
> class SpringApp
> {
> public:
> SpringApp (); //!< Constructor
> ~SpringApp (); //!< Destructor
>
> int Run(int argc, char *argv[]); //!< Run game loop
>
> protected:
> bool Initialize (); //!< Initialize app
> void CheckCmdLineFile (int argc,char *argv[]); //!< Check command line for files
> bool ParseCmdLine(); //!< Parse command line
> void InitVFS (); //!< Initialize VFS
> void CreateGameSetup (); //!< Creates GameSetup
> bool InitWindow (const char* title); //!< Initializes window
> void InitOpenGL (); //!< Initializes OpenGL
> bool SetSDLVideoMode(); //!< Sets SDL video mode
> void Shutdown (); //!< Shuts down application
> int Draw (); //!< Repeated draw function
> void UpdateSDLKeys (); //!< Update SDL key array
>
> /**
> * @brief command line
> *
> * Pointer to instance of commandline parser
> */
> BaseCmd *cmdline;
>
> /**
> * @brief demofile
> *
> * Name of a demofile
> */
> string demofile;
>
> /**
> * @brief startscript
> *
> * Name of a start script
> */
> string startscript;
>
> /**
> * @brief screen width
> *
> * Game screen width
> */
> int screenWidth;
>
> /**
> * @brief screen height
> *
> * Game screen height
> */
> int screenHeight;
>
> /**
> * @brief screen freq
> *
> * Game screen frequency
> */
> int screenFreq;
>
> /**
> * @brief active
> *
> * Whether game is active
> */
> bool active;
>
> /**
> * @brief FSAA
> *
> * Level of fullscreen anti-aliasing
> */
> bool FSAA;
> };
63,66d178
< /**************************
< * SpringApp definitions: *
< **************************/
<
637,651d748
< /**
< * @brief Clean exit durring a major error
< *
< * A call to "exit(retCode)" will not call our destructor
< * for SpringApp. This function is needed to exit cleanly.
< */
< /*static*/ void SpringApp::ExitCleanFromAnywhere(int retCode)
< {
< // Cleanup before an exit
< g_pMySpringAppInstance->Shutdown();
<
< // Hokay, time for an exit
< exit(retCode);
< }
<
697d793
< g_pMySpringAppInstance = &app;
705d800
< g_pMySpringAppInstance = &app;
Simple enough, I built ran and crashed spring (old video card... that was given to a friend by a friend of the friend because it had lost a fan, and wouldn't work 0.o). My version crashes and restores video modes (ie: releases anything that really needs to be), the old version doesn't.