some memory leak cleanup
This commit is contained in:
parent
2d8f0f7430
commit
4e1c9be664
|
@ -45,17 +45,10 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||||
slotLinesYBase=650;
|
slotLinesYBase=650;
|
||||||
slotsLineHeight=30;
|
slotsLineHeight=30;
|
||||||
previewTexture=NULL;
|
previewTexture=NULL;
|
||||||
needsToBeFreedTexture=NULL;
|
|
||||||
buttonToDelete=NULL;
|
buttonToDelete=NULL;
|
||||||
|
|
||||||
selectedButton=NULL;
|
selectedButton=NULL;
|
||||||
|
|
||||||
// string userData = Config::getInstance().getString("UserData_Root","");
|
|
||||||
// if(userData != "") {
|
|
||||||
// endPathWithSlash(userData);
|
|
||||||
// }
|
|
||||||
// saveGameDir = userData +"saved";
|
|
||||||
// endPathWithSlash(saveGameDir);
|
|
||||||
string userData = Config::getInstance().getString("UserData_Root","");
|
string userData = Config::getInstance().getString("UserData_Root","");
|
||||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||||
userData = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey);
|
userData = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey);
|
||||||
|
@ -67,7 +60,6 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||||
|
|
||||||
lines[0].init(0,slotLinesYBase+slotsLineHeight);
|
lines[0].init(0,slotLinesYBase+slotsLineHeight);
|
||||||
lines[1].init(0, slotLinesYBase-(slotsToRender-1)*slotsLineHeight-5);
|
lines[1].init(0, slotLinesYBase-(slotsToRender-1)*slotsLineHeight-5);
|
||||||
//lines[1].setHorizontal(false);
|
|
||||||
|
|
||||||
headerLabel.registerGraphicComponent(containerName,"headerLabel");
|
headerLabel.registerGraphicComponent(containerName,"headerLabel");
|
||||||
headerLabel.init(400, 730);
|
headerLabel.init(400, 730);
|
||||||
|
@ -95,9 +87,6 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||||
|
|
||||||
infoTextLabel.registerGraphicComponent(containerName,"infoTextLabel");
|
infoTextLabel.registerGraphicComponent(containerName,"infoTextLabel");
|
||||||
infoTextLabel.init(550, 350);
|
infoTextLabel.init(550, 350);
|
||||||
// infoTextLabel.setFont(CoreData::getInstance().getMenuFontBig());
|
|
||||||
// infoTextLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
|
||||||
//infoTextLabel.setText("Info block for the current slot, maybe screenshot above \ntest\ntest2");
|
|
||||||
infoTextLabel.setText("");
|
infoTextLabel.setText("");
|
||||||
|
|
||||||
abortButton.registerGraphicComponent(containerName,"abortButton");
|
abortButton.registerGraphicComponent(containerName,"abortButton");
|
||||||
|
@ -131,20 +120,20 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||||
MenuStateLoadGame::~MenuStateLoadGame() {
|
MenuStateLoadGame::~MenuStateLoadGame() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
clearSlots();
|
clearSlots();
|
||||||
if(needsToBeFreedTexture!=NULL){
|
|
||||||
needsToBeFreedTexture->end();
|
cleanupTexture(&previewTexture);
|
||||||
delete needsToBeFreedTexture;
|
|
||||||
needsToBeFreedTexture=NULL;
|
|
||||||
}
|
|
||||||
if(previewTexture!=NULL){
|
|
||||||
previewTexture->end();
|
|
||||||
delete previewTexture;
|
|
||||||
previewTexture=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuStateLoadGame::cleanupTexture(Texture2D **texture) {
|
||||||
|
if(texture != NULL && *texture != NULL) {
|
||||||
|
(*texture)->end();
|
||||||
|
delete *texture;
|
||||||
|
*texture=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MenuStateLoadGame::clearSlots() {
|
void MenuStateLoadGame::clearSlots() {
|
||||||
while(!slots.empty()) {
|
while(!slots.empty()) {
|
||||||
delete slots.back();
|
delete slots.back();
|
||||||
|
@ -166,13 +155,10 @@ void MenuStateLoadGame::listFiles() {
|
||||||
filenames.clear();
|
filenames.clear();
|
||||||
findAll(paths, "*.xml", filenames, true, false, true);
|
findAll(paths, "*.xml", filenames, true, false, true);
|
||||||
sort(filenames.begin(),filenames.end());
|
sort(filenames.begin(),filenames.end());
|
||||||
//printf("filenames = %d\n",filenames.size());
|
|
||||||
for(int i = (int)filenames.size()-1; i > -1; i--) {
|
for(int i = (int)filenames.size()-1; i > -1; i--) {
|
||||||
GraphicButton *button=new GraphicButton();
|
GraphicButton *button=new GraphicButton();
|
||||||
button->init( keyButtonsXBase, keyButtonsYBase, keyButtonsWidth,keyButtonsHeight);
|
button->init( keyButtonsXBase, keyButtonsYBase, keyButtonsWidth,keyButtonsHeight);
|
||||||
button->setText(filenames[i]);
|
button->setText(filenames[i]);
|
||||||
// button->setCustomTexture(CoreData::getInstance().getCustomTexture());
|
|
||||||
// button->setUseCustomTexture(true);
|
|
||||||
|
|
||||||
slots.push_back(button);
|
slots.push_back(button);
|
||||||
slotsGB.push_back(button);
|
slotsGB.push_back(button);
|
||||||
|
@ -183,6 +169,11 @@ void MenuStateLoadGame::listFiles() {
|
||||||
void MenuStateLoadGame::reloadUI() {
|
void MenuStateLoadGame::reloadUI() {
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
|
infoHeaderLabel.setText(lang.getString("SavegameInfo"));
|
||||||
|
savedGamesLabel.setText(lang.getString("SavedGames"));
|
||||||
|
noSavedGamesLabel.setText(lang.getString("NoSavedGames"));
|
||||||
|
headerLabel.setText(lang.getString("LoadGameMenu"));
|
||||||
|
|
||||||
abortButton.setText(lang.getString("Abort"));
|
abortButton.setText(lang.getString("Abort"));
|
||||||
deleteButton.setText(lang.getString("Delete"));
|
deleteButton.setText(lang.getString("Delete"));
|
||||||
loadButton.setText(lang.getString("LoadGame"));
|
loadButton.setText(lang.getString("LoadGame"));
|
||||||
|
@ -229,12 +220,11 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
|
|
||||||
for(int i = 0; i < slots.size(); i++) {
|
for(int i = 0; i < slots.size(); i++) {
|
||||||
if(slots[i] == selectedButton) {
|
if(slots[i] == selectedButton) {
|
||||||
//deleteSlot(i);
|
|
||||||
if(removeFile(filename) == true) {
|
if(removeFile(filename) == true) {
|
||||||
removeFile(jpgfilename);
|
removeFile(jpgfilename);
|
||||||
removeFile(replayfilename);
|
removeFile(replayfilename);
|
||||||
needsToBeFreedTexture=previewTexture;
|
cleanupTexture(&previewTexture);
|
||||||
previewTexture=NULL;
|
|
||||||
infoTextLabel.setText("");
|
infoTextLabel.setText("");
|
||||||
listFiles();
|
listFiles();
|
||||||
slotsScrollBar.setElementCount((int)filenames.size());
|
slotsScrollBar.setElementCount((int)filenames.size());
|
||||||
|
@ -245,7 +235,6 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
|
||||||
}
|
}
|
||||||
else if(loadButton.mouseClick(x, y)) {
|
else if(loadButton.mouseClick(x, y)) {
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
|
@ -269,7 +258,6 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
|
||||||
}
|
}
|
||||||
else if(slotsScrollBar.mouseClick(x, y)){
|
else if(slotsScrollBar.mouseClick(x, y)){
|
||||||
soundRenderer.playFx(coreData.getClickSoundA());
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
|
@ -280,11 +268,11 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
if(slots[i]->mouseClick(x, y) && selectedButton != slots[i]) {
|
if(slots[i]->mouseClick(x, y) && selectedButton != slots[i]) {
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
|
|
||||||
needsToBeFreedTexture = previewTexture;
|
cleanupTexture(&previewTexture);
|
||||||
selectedButton = slots[i];
|
selectedButton = slots[i];
|
||||||
string filename = saveGameDir + selectedButton->getText()+".xml";
|
string filename = saveGameDir + selectedButton->getText()+".xml";
|
||||||
string screenShotFilename = filename + ".jpg";
|
string screenShotFilename = filename + ".jpg";
|
||||||
if(fileExists(screenShotFilename)) {
|
if(fileExists(screenShotFilename) == true) {
|
||||||
previewTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
previewTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
||||||
if(previewTexture) {
|
if(previewTexture) {
|
||||||
previewTexture->setMipmap(true);
|
previewTexture->setMipmap(true);
|
||||||
|
@ -296,7 +284,7 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
previewTexture=NULL;
|
previewTexture=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileExists(filename)) {
|
if(fileExists(filename) == true) {
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
XmlTree xmlTree(XML_RAPIDXML_ENGINE);
|
XmlTree xmlTree(XML_RAPIDXML_ENGINE);
|
||||||
|
@ -322,7 +310,6 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
GameSettings newGameSettings;
|
GameSettings newGameSettings;
|
||||||
newGameSettings.loadGame(gameNode);
|
newGameSettings.loadGame(gameNode);
|
||||||
|
|
||||||
//LoadSavedGameInfo=Map: %s\nTileset: %s\nTech: %s\nScenario: %s\n# players: %d\nFaction: %s
|
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,lang.getString("LoadSavedGameInfo").c_str(),
|
snprintf(szBuf,8096,lang.getString("LoadSavedGameInfo").c_str(),
|
||||||
newGameSettings.getMap().c_str(),
|
newGameSettings.getMap().c_str(),
|
||||||
|
@ -347,20 +334,13 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateLoadGame::mouseUp(int x, int y, const MouseButton mouseButton){
|
void MenuStateLoadGame::mouseUp(int x, int y, const MouseButton mouseButton) {
|
||||||
if (mouseButton == mbLeft) {
|
if (mouseButton == mbLeft) {
|
||||||
slotsScrollBar.mouseUp(x, y);
|
slotsScrollBar.mouseUp(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void MenuStateLoadGame::deleteSlot(int i){
|
void MenuStateLoadGame::mouseMove(int x, int y, const MouseState *ms) {
|
||||||
// if(selectedButton==slots[i]){
|
|
||||||
// selectedButton=NULL;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void MenuStateLoadGame::mouseMove(int x, int y, const MouseState *ms){
|
|
||||||
|
|
||||||
abortButton.mouseMove(x, y);
|
abortButton.mouseMove(x, y);
|
||||||
deleteButton.mouseMove(x, y);
|
deleteButton.mouseMove(x, y);
|
||||||
loadButton.mouseMove(x, y);
|
loadButton.mouseMove(x, y);
|
||||||
|
@ -370,10 +350,9 @@ void MenuStateLoadGame::mouseMove(int x, int y, const MouseState *ms){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slotsScrollBar.mouseMove(x,y);
|
slotsScrollBar.mouseMove(x,y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateLoadGame::render(){
|
void MenuStateLoadGame::render() {
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
renderer.renderLabel(&headerLabel);
|
renderer.renderLabel(&headerLabel);
|
||||||
|
@ -415,16 +394,6 @@ void MenuStateLoadGame::render(){
|
||||||
|
|
||||||
renderer.renderConsole(&console,false,false);
|
renderer.renderConsole(&console,false,false);
|
||||||
if(program != NULL) program->renderProgramMsgBox();
|
if(program != NULL) program->renderProgramMsgBox();
|
||||||
|
|
||||||
if(needsToBeFreedTexture!=NULL){
|
|
||||||
needsToBeFreedTexture->end();
|
|
||||||
delete needsToBeFreedTexture;
|
|
||||||
needsToBeFreedTexture=NULL;
|
|
||||||
}
|
|
||||||
// if(buttonToDelete!=NULL){
|
|
||||||
// delete buttonToDelete;
|
|
||||||
// buttonToDelete=NULL;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateLoadGame::update(){
|
void MenuStateLoadGame::update(){
|
||||||
|
@ -438,11 +407,8 @@ void MenuStateLoadGame::update(){
|
||||||
|
|
||||||
void MenuStateLoadGame::keyDown(SDL_KeyboardEvent key) {
|
void MenuStateLoadGame::keyDown(SDL_KeyboardEvent key) {
|
||||||
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
||||||
//if(key == configKeys.getCharKey("SaveGUILayout")) {
|
|
||||||
if(isKeyPressed(configKeys.getSDLKey("SaveGUILayout"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("SaveGUILayout"),key) == true) {
|
||||||
GraphicComponent::saveAllCustomProperties(containerName);
|
GraphicComponent::saveAllCustomProperties(containerName);
|
||||||
//Lang &lang= Lang::getInstance();
|
|
||||||
//console.addLine(lang.getString("GUILayoutSaved") + " [" + (saved ? lang.getString("Yes") : lang.getString("No"))+ "]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ private:
|
||||||
GraphicButton* buttonToDelete;
|
GraphicButton* buttonToDelete;
|
||||||
|
|
||||||
Texture2D *previewTexture;
|
Texture2D *previewTexture;
|
||||||
Texture2D *needsToBeFreedTexture;
|
|
||||||
|
|
||||||
GraphicLabel headerLabel;
|
GraphicLabel headerLabel;
|
||||||
GraphicLabel noSavedGamesLabel;
|
GraphicLabel noSavedGamesLabel;
|
||||||
|
@ -67,10 +66,11 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void clearSlots();
|
void clearSlots();
|
||||||
//void deleteSlot(int i);
|
|
||||||
void listFiles();
|
void listFiles();
|
||||||
|
|
||||||
void showMessageBox(const string &text, const string &header, bool toggle);
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||||
|
|
||||||
|
void cleanupTexture(Texture2D **texture);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,10 +63,7 @@ World::World() {
|
||||||
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
|
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
|
||||||
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
|
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
|
||||||
|
|
||||||
//MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str());
|
|
||||||
|
|
||||||
frameCount= 0;
|
frameCount= 0;
|
||||||
//nextUnitId= 0;
|
|
||||||
|
|
||||||
scriptManager= NULL;
|
scriptManager= NULL;
|
||||||
this->game = NULL;
|
this->game = NULL;
|
||||||
|
|
|
@ -685,6 +685,7 @@ void Font::bidi_cvt(string &str_) {
|
||||||
|
|
||||||
//Free allocated memory
|
//Free allocated memory
|
||||||
delete [] ltov;
|
delete [] ltov;
|
||||||
|
delete [] vtol;
|
||||||
delete [] visual;
|
delete [] visual;
|
||||||
delete [] logical;
|
delete [] logical;
|
||||||
delete [] ip;
|
delete [] ip;
|
||||||
|
|
|
@ -34,6 +34,7 @@ FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() {
|
||||||
workerThreadTechPaths.clear();
|
workerThreadTechPaths.clear();
|
||||||
preCacheWorkerThreadList.clear();
|
preCacheWorkerThreadList.clear();
|
||||||
processTechCB = NULL;
|
processTechCB = NULL;
|
||||||
|
pauseForGame = false;
|
||||||
uniqueID = "FileCRCPreCacheThread";
|
uniqueID = "FileCRCPreCacheThread";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ FileCRCPreCacheThread::FileCRCPreCacheThread(vector<string> techDataPaths,
|
||||||
this->workerThreadTechPaths = workerThreadTechPaths;
|
this->workerThreadTechPaths = workerThreadTechPaths;
|
||||||
preCacheWorkerThreadList.clear();
|
preCacheWorkerThreadList.clear();
|
||||||
this->processTechCB = processTechCB;
|
this->processTechCB = processTechCB;
|
||||||
|
pauseForGame = false;
|
||||||
uniqueID = "FileCRCPreCacheThread";
|
uniqueID = "FileCRCPreCacheThread";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -400,6 +400,10 @@ XmlNode *XmlIoRapid::load(const string &path, const std::map<string,string> &map
|
||||||
|
|
||||||
rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues);
|
rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues);
|
||||||
|
|
||||||
|
//doc->clear();
|
||||||
|
cleanup();
|
||||||
|
init();
|
||||||
|
|
||||||
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
#if defined(WIN32) && !defined(__MINGW32__)
|
#if defined(WIN32) && !defined(__MINGW32__)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user