1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- fixed some evil memory leaks

- fixed recursive dependency of castles
This commit is contained in:
Ivan Savenko 2013-12-19 19:43:16 +00:00
parent 881a7cf862
commit 29f4a12814
13 changed files with 27 additions and 19 deletions

View File

@ -735,6 +735,12 @@ void dispose()
{ {
if (console) if (console)
delete console; delete console;
// cleanup, mostly to remove false leaks from analyzer
CResourceHandler::clear();
CCS->musich->release();
CCS->soundh->release();
CMessage::dispose();
} }
//used only once during initialization //used only once during initialization

View File

@ -501,8 +501,8 @@ void MusicEntry::load(std::string musicURI)
logGlobal->traceStream()<<"Loading music file "<<musicURI; logGlobal->traceStream()<<"Loading music file "<<musicURI;
auto data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll(); data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll();
musicFile = SDL_RWFromConstMem(data.first.release(), data.second); musicFile = SDL_RWFromConstMem(data.first.get(), data.second);
music = Mix_LoadMUS_RW(musicFile); music = Mix_LoadMUS_RW(musicFile);
if(!music) if(!music)

View File

@ -85,6 +85,7 @@ class CMusicHandler;
//Class for handling one music file //Class for handling one music file
class MusicEntry class MusicEntry
{ {
std::pair<std::unique_ptr<ui8[]>, size_t> data;
CMusicHandler *owner; CMusicHandler *owner;
Mix_Music *music; Mix_Music *music;
SDL_RWops *musicFile; SDL_RWops *musicFile;

View File

@ -160,7 +160,7 @@
"shipyard": { "id" : 6 }, "shipyard": { "id" : 6 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -154,7 +154,7 @@
"tavern": { "id" : 5 }, "tavern": { "id" : 5 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -153,7 +153,7 @@
"shipyard": { "id" : 6 }, "shipyard": { "id" : 6 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -155,7 +155,7 @@
"tavern": { "id" : 5 }, "tavern": { "id" : 5 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -159,7 +159,7 @@
"shipyard": { "id" : 6 }, "shipyard": { "id" : 6 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -159,7 +159,7 @@
"tavern": { "id" : 5 }, "tavern": { "id" : 5 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -150,7 +150,7 @@
"tavern": { "id" : 5 }, "tavern": { "id" : 5 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -154,7 +154,7 @@
"tavern": { "id" : 5 }, "tavern": { "id" : 5 },
"fort": { "id" : 7 }, "fort": { "id" : 7 },
"citadel": { "id" : 8, "upgrades" : "fort" }, "citadel": { "id" : 8, "upgrades" : "fort" },
"castle": { "id" : 9, "upgrades" : "castle" }, "castle": { "id" : 9, "upgrades" : "citadel" },
"villageHall": { "id" : 10, "mode" : "auto" }, "villageHall": { "id" : 10, "mode" : "auto" },
"townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] }, "townHall": { "id" : 11, "upgrades" : "villageHall", "requires" : [ "tavern" ] },
"cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] }, "cityHall": { "id" : 12, "upgrades" : "townHall", "requires" : [ "allOf", [ "mageGuild1" ], [ "marketplace" ], [ "blacksmith" ] ] },

View File

@ -311,18 +311,18 @@ void CTownHandler::loadBuilding(CTown &town, const std::string & stringID, const
ret->upgrade = BuildingID(source["upgrades"].Float()); ret->upgrade = BuildingID(source["upgrades"].Float());
else else
{ {
// building id and upgrades can't be the same
if(stringID == source["upgrades"].String())
{
throw std::runtime_error(boost::str(boost::format("Building with ID '%s' of town '%s' can't be an upgrade of the same building.") %
stringID % town.faction->name));
}
VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, source["upgrades"], [=](si32 identifier) VLC->modh->identifiers.requestIdentifier("building." + town.faction->identifier, source["upgrades"], [=](si32 identifier)
{ {
ret->upgrade = BuildingID(identifier); ret->upgrade = BuildingID(identifier);
}); });
} }
// building id and upgrades can't be the same
if(ret->upgrade == ret->bid)
{
throw std::runtime_error(boost::str(boost::format("Building with ID '%s' of town '%s' can't be an upgrade of the same building.") %
stringID % town.faction->name));
}
} }
else else
ret->upgrade = BuildingID::NONE; ret->upgrade = BuildingID::NONE;

View File

@ -102,7 +102,8 @@ CCompressedStream::CCompressedStream(std::unique_ptr<CInputStream> stream, bool
CCompressedStream::~CCompressedStream() CCompressedStream::~CCompressedStream()
{ {
delete inflateState; inflateEnd(inflateState);
//delete inflateState;
} }
si64 CCompressedStream::readMore(ui8 *data, si64 size) si64 CCompressedStream::readMore(ui8 *data, si64 size)
@ -163,7 +164,7 @@ si64 CCompressedStream::readMore(ui8 *data, si64 size)
if (fileEnded) if (fileEnded)
{ {
inflateEnd(inflateState); inflateEnd(inflateState);
vstd::clear_pointer(inflateState); //vstd::clear_pointer(inflateState);
} }
return decompressed; return decompressed;
} }