From 8a6162ba157188b7f25d8f30755a9c67eb6dc562 Mon Sep 17 00:00:00 2001 From: "wagic.jeck" Date: Mon, 26 Oct 2009 02:27:55 +0000 Subject: [PATCH] Jeck - Please review. Disconcertingly enough, this seems to resolve issue 109. Ran demo mode for 1 hour (w00t no crashes!), played five manual games, shop appeared fine... but why would an mObject ever be null? I'm not so sure about this commit. It "fixes" the issue, but doesn't do anything for the underlying cause. For all I know, I might just not have re-encountered issue 109 yet... still, it's not a /bad/ commit. In the worst case, it does some unnecessary sanity checking. There's potential for a a hang if item is NULL in Update(), if input doesn't get passed along in a way that allows the player to exit... But I think that's what the call to JGuiController::Update is for. Thoughts? --- projects/mtg/src/ShopItem.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index 1effd29fb..a14969248 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -248,17 +248,21 @@ void ShopItems::Update(float dt){ }else{ if (showPriceDialog!=-1){ ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]); - int price = item->price; - char buffer[4096]; - sprintf(buffer,"%s : %i credits",item->getText(),price); - if(!dialog){ - dialog = NEW SimpleMenu(1,this,resources.GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); - dialog->Add(1,"Yes"); - dialog->Add(2,"No"); - } - else{ - dialog->Update(dt); + if(item){ + int price = item->price; + char buffer[4096]; + sprintf(buffer,"%s : %i credits",item->getText(),price); + if(!dialog){ + dialog = NEW SimpleMenu(1,this,resources.GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); + dialog->Add(1,"Yes"); + dialog->Add(2,"No"); + } + else{ + dialog->Update(dt); + } } + else + JGuiController::Update(dt); }else{ u32 buttons[] = {PSP_CTRL_LEFT,PSP_CTRL_DOWN,PSP_CTRL_RIGHT,PSP_CTRL_UP,PSP_CTRL_CIRCLE}; for (int i = 0; i < 5; ++i){ @@ -313,7 +317,8 @@ void ShopItems::Render(){ if(mCurr >= 0){ mFont->SetColor(ARGB(255,255,255,0)); ShopItem * item = ((ShopItem *)mObjects[mCurr]); - mFont->DrawString(item->mText.c_str(), SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT - 14,JGETEXT_CENTER); + if(item) + mFont->DrawString(item->mText.c_str(), SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT - 14,JGETEXT_CENTER); mFont->SetColor(ARGB(255,255,255,255)); } @@ -326,7 +331,7 @@ void ShopItems::Render(){ if (i == mCurr) mFont->SetColor(ARGB(255,255,255,0)); else mFont->SetColor(ARGB(255,255,255,255)); char buffer[512]; - sprintf(buffer, "%s", s->getText()); + sprintf(buffer, "%s", s ? s->getText() : "error"); float x = 300; float y = 10 + 20*i; mFont->DrawString(buffer,x,y);