- fixed a few memory leaks
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-03-29 10:33:42 +00:00
parent 2f66c4953f
commit 3994006d7e
12 changed files with 64 additions and 33 deletions

View File

@@ -24,6 +24,7 @@ class ActionLayer: public GuiLayer, public JGuiListener{
int unstopableRenderInProgress();
bool CheckUserInput(u32 key);
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;};
~ActionLayer();
int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card);
int receiveEvent(WEvent * event);

View File

@@ -33,6 +33,7 @@ class SimpleMenu:public JGuiController{
static unsigned int refCount;
static JQuad *spadeR, *spadeL, *jewel, *side;
static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex;
static JLBFont* titleFont;
static hgeParticleSystem* stars;
// This works only because of no multithreading
@@ -51,6 +52,7 @@ class SimpleMenu:public JGuiController{
float selectionTargetY;
bool closed;
static void destroy();
};

View File

@@ -76,6 +76,7 @@ protected:
~SampleCache();
public:
static SampleCache * GetInstance();
static void DestroyInstance();
SampleCache(){lastTime = 0;};
JSample * getSample(string filename);

View File

@@ -515,7 +515,7 @@ AIStats * AIPlayer::getStats(){
if (!stats){
char statFile[512];
sprintf(statFile, RESPATH"/ai/baka/stats/%s.stats", opponent()->deckFile.c_str());
stats = new AIStats(this, statFile);
stats = NEW AIStats(this, statFile);
}
return stats;
}

View File

@@ -216,3 +216,7 @@ void ActionLayer::ButtonPressed(int controllerid, int controlid){
menuObject = 0;
}
ActionLayer::~ActionLayer(){
SAFE_DELETE(abilitiesMenu);
}

View File

@@ -170,6 +170,8 @@ void GameApp::Destroy()
SAFE_DELETE(collection);
}
SAFE_DELETE(cache);
SampleCache::DestroyInstance();
SAFE_DELETE(CommonRes);
@@ -181,6 +183,10 @@ void GameApp::Destroy()
SAFE_DELETE(music);
delete(DeckStats::GetInstance());
SimpleMenu::destroy();
LOG("==Destroying GameApp Successful==");
}

View File

@@ -44,6 +44,7 @@ void GameStateOptions::End()
{
JRenderer::GetInstance()->EnableVSync(false);
SAFE_DELETE(optionsList);
SAFE_DELETE(optionsMenu);
}

View File

@@ -77,12 +77,9 @@ void GameStateShop::End()
SAFE_DELETE(shop);
SAFE_DELETE(mBack);
SAFE_DELETE(backTexture);
if(bgTexture)
SAFE_DELETE(bgTexture);
if(mBg)
SAFE_DELETE(mBg);
if(menu)
SAFE_DELETE(menu);
SAFE_DELETE(bgTexture);
SAFE_DELETE(mBg);
SAFE_DELETE(menu);
}

View File

@@ -30,11 +30,12 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
}
MTGPlayerCards::~MTGPlayerCards(){
if(library) delete library;
if(graveyard) delete graveyard;
if(hand) delete hand;
if(inPlay) delete inPlay;
if(stack) delete stack;
SAFE_DELETE(library);
SAFE_DELETE(graveyard);
SAFE_DELETE(hand);
SAFE_DELETE(inPlay);
SAFE_DELETE(stack);
SAFE_DELETE(removedFromGame);
}
void MTGPlayerCards::setOwner(Player * player){
@@ -62,7 +63,6 @@ void MTGPlayerCards::init(){
hand = NEW MTGHand();
inPlay = NEW MTGInPlay();
stack = NEW MTGStack();
stack = NEW MTGStack();
removedFromGame = NEW MTGRemovedFromGame();
}

View File

@@ -63,7 +63,6 @@ void ShopItem::Render(){
renderer->RenderQuad(quad,mX + SCREEN_WIDTH/2 + 20,5,0, 0.9f,0.9f);
}else{
if (card) CardGui::alternateRender(card,NULL,mX + SCREEN_WIDTH/2 + 100 + 20,133,0, 0.9f);
//TODO
}
mFont->SetColor(ARGB(255,255,255,0));
}else{
@@ -80,18 +79,15 @@ void ShopItem::Render(){
void ShopItem::Update(float dt)
{
if (mScale < mTargetScale)
{
if (mScale < mTargetScale){
mScale += 8.0f*dt;
if (mScale > mTargetScale)
mScale = mTargetScale;
}
else if (mScale > mTargetScale)
{
mScale = mTargetScale;
}else if (mScale > mTargetScale){
mScale -= 8.0f*dt;
if (mScale < mTargetScale)
mScale = mTargetScale;
}
mScale = mTargetScale;
}
}
@@ -157,9 +153,9 @@ void ShopItems::Update(float dt){
char buffer[4096];
sprintf(buffer,"%s : %i credits",item->getText(),price);
if(!dialog){
dialog = NEW SimpleMenu(1,this,GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
dialog->Add(1,"Yes");
dialog->Add(2,"No");
dialog = NEW SimpleMenu(1,this,GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
dialog->Add(1,"Yes");
dialog->Add(2,"No");
}
else{
dialog->Update(dt);
@@ -220,7 +216,7 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
item->quantity--;
}else{
safeDeleteDisplay();
display = new CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
int curNbcards = playerdata->collection->totalCards();
//if (showPriceDialog == 0){
// //Starter Deck

View File

@@ -18,6 +18,10 @@ JQuad* SimpleMenu::spadeR = NULL;
JQuad* SimpleMenu::spadeL = NULL;
JQuad* SimpleMenu::jewel = NULL;
JQuad* SimpleMenu::side = NULL;
JTexture* SimpleMenu::spadeRTex = NULL;
JTexture* SimpleMenu::spadeLTex = NULL;
JTexture* SimpleMenu::jewelTex = NULL;
JTexture* SimpleMenu::sideTex = NULL;
JLBFont* SimpleMenu::titleFont = NULL;
hgeParticleSystem* SimpleMenu::stars = NULL;
unsigned int SimpleMenu::refCount = 0;
@@ -36,21 +40,22 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int
title = _title;
startId = 0;
maxItems = _maxItems;
side = NULL;
selectionT = 0;
timeOpen = 0;
closed = false;
++refCount;
JRenderer* renderer = JRenderer::GetInstance();
static JTexture* spadeLTex = renderer->LoadTexture(spadeLPath, TEX_TYPE_USE_VRAM);
static JTexture* spadeRTex = renderer->LoadTexture(spadeRPath, TEX_TYPE_USE_VRAM);
static JTexture* jewelTex = renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM);
static JTexture* sideTex = renderer->LoadTexture(sidePath, TEX_TYPE_USE_VRAM);
if (NULL == spadeL) spadeL = NEW JQuad(spadeLTex, 2, 1, 16, 13);
if (!spadeLTex) spadeLTex= renderer->LoadTexture(spadeLPath, TEX_TYPE_USE_VRAM);
if (!spadeRTex) spadeRTex = renderer->LoadTexture(spadeRPath, TEX_TYPE_USE_VRAM);
if (!jewelTex) jewelTex= renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM);
if (!sideTex) sideTex = renderer->LoadTexture(sidePath, TEX_TYPE_USE_VRAM);
if (NULL == spadeL) spadeL = NEW JQuad(spadeLTex, 2, 1, 16, 13);
if (NULL == spadeR) spadeR = NEW JQuad(spadeRTex, 2, 1, 16, 13);
if (NULL == jewel) jewel = NEW JQuad(jewelTex, 1, 1, 3, 3);
if (NULL == side) side = NEW JQuad(sideTex, 1, 1, 1, 7);
if (NULL == titleFont)
{
GameApp::CommonRes->LoadJLBFont(titleFontPath, 7);
@@ -172,3 +177,15 @@ void SimpleMenu::Close()
timeOpen = -1.0;
stars->Stop(true);
}
void SimpleMenu::destroy(){
SAFE_DELETE(SimpleMenu::spadeR);
SAFE_DELETE(SimpleMenu::spadeL);
SAFE_DELETE(SimpleMenu::jewel);
SAFE_DELETE(SimpleMenu::side);
SAFE_DELETE(SimpleMenu::spadeRTex);
SAFE_DELETE(SimpleMenu::spadeLTex);
SAFE_DELETE(SimpleMenu::jewelTex);
SAFE_DELETE(SimpleMenu::sideTex);
SAFE_DELETE(SimpleMenu::stars);
}

View File

@@ -93,6 +93,7 @@ CardTexture::CardTexture(MTGCard * card, int _type): type(_type){
LOG("==Creating CardTexture Object");
char filename[100];
quad = NULL;
tex = NULL;
nbpixels = 0;
lastTime = 0;
if (type == CACHE_THUMB){
@@ -103,7 +104,8 @@ CardTexture::CardTexture(MTGCard * card, int _type): type(_type){
#ifdef WIN32
OutputDebugString(filename);
#endif
tex = JRenderer::GetInstance()->LoadTexture(filename, false);
if (fileExists(filename))
tex = JRenderer::GetInstance()->LoadTexture(filename, false);
if (tex){
quad = NEW JQuad(tex, 0.0f, 0.0f, tex->mWidth, tex->mHeight);
nbpixels = tex->mTexHeight * tex->mTexWidth;
@@ -177,3 +179,7 @@ void SampleCache::cleanCache(){
SampleCache::~SampleCache(){
cleanCache();
}
void SampleCache::DestroyInstance(){
SAFE_DELETE(mInstance);
}