Changeset - r9159:0c3d5148cb9a
[Not reviewed]
master
0 2 0
smatz - 16 years ago 2008-05-08 23:26:17
smatz@openttd.org
(svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
2 files changed with 36 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/driver.h
Show inline comments
 
@@ -43,7 +43,7 @@ private:
 

	
 
	static Drivers &GetDrivers()
 
	{
 
		static Drivers &s_drivers = *new Drivers();
 
		static Drivers s_drivers;
 
		return s_drivers;
 
	}
 

	
 
@@ -67,7 +67,23 @@ public:
 
		name(NULL)
 
	{}
 

	
 
	virtual ~DriverFactoryBase() { if (this->name != NULL) GetDrivers().erase(this->name); free(this->name); }
 
	/** Frees memory used for this->name
 
	 */
 
	virtual ~DriverFactoryBase() {
 
		if (this->name == NULL) return;
 
		GetDrivers().erase(this->name);
 
		free(this->name);
 
	}
 

	
 
	/** Shuts down all active drivers
 
	 */
 
	static void ShutdownDrivers()
 
	{
 
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
 
			Driver *driver = *GetActiveDriver(dt);
 
			if (driver != NULL) driver->Stop();
 
		}
 
	}
 

	
 
	static const Driver *SelectDriver(const char *name, Driver::Type type);
 
	static char *GetDriversInfo(char *p, const char *last);
src/openttd.cpp
Show inline comments
 
@@ -288,8 +288,20 @@ static void InitializeDynamicVariables()
 
}
 

	
 

	
 
static void UnInitializeGame()
 
/** Unitializes drivers, frees allocated memory, cleans pools, ...
 
 * Generally, prepares the game for shutting down
 
 */
 
static void ShutdownGame()
 
{
 
	/* stop the AI */
 
	AI_Uninitialize();
 

	
 
	IConsoleFree();
 

	
 
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
 

	
 
	DriverFactoryBase::ShutdownDrivers();
 

	
 
	UnInitWindowSystem();
 

	
 
	/* Uninitialize airport state machines */
 
@@ -310,6 +322,9 @@ static void UnInitializeGame()
 
	free((void*)_industry_sort);
 

	
 
	free(_config_file);
 

	
 
	/* Close all and any open filehandles */
 
	FioCloseAll();
 
}
 

	
 
static void LoadIntroGame()
 
@@ -623,13 +638,6 @@ int ttd_main(int argc, char *argv[])
 
	_video_driver->MainLoop();
 

	
 
	WaitTillSaved();
 
	IConsoleFree();
 

	
 
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
 

	
 
	_video_driver->Stop();
 
	_music_driver->Stop();
 
	_sound_driver->Stop();
 

	
 
	/* only save config if we have to */
 
	if (save_config) {
 
@@ -637,14 +645,8 @@ int ttd_main(int argc, char *argv[])
 
		SaveToHighScore();
 
	}
 

	
 
	/* Reset windowing system and free config file */
 
	UnInitializeGame();
 

	
 
	/* stop the AI */
 
	AI_Uninitialize();
 

	
 
	/* Close all and any open filehandles */
 
	FioCloseAll();
 
	/* Reset windowing system, stop drivers, free used memory, ... */
 
	ShutdownGame();
 

	
 
	return 0;
 
}
0 comments (0 inline, 0 general)