PINK: Simplify and fix PDAPage object creation

Avoid mixing objects on the stack and heap. This simplifies the code,
and fixes crashes when changing pages in the PDA
This commit is contained in:
Filippos Karapetis 2020-02-29 02:21:13 +02:00
parent d8350221f0
commit d486799ea7
4 changed files with 10 additions and 17 deletions

View File

@ -27,11 +27,10 @@
namespace Pink {
PDAPage PDAPage::create(const Common::String &pageName, PDAMgr &pdaMgr) {
PDAPage page(pageName);
page._name = pageName;
page._resMgr.init(pdaMgr.getGame(), &page);
return page;
PDAPage::PDAPage(const Common::String& name, PinkEngine *vm) {
_name = name;
_resMgr.init(vm, this);
init();
}
} // End of namespace Pink

View File

@ -31,10 +31,7 @@ class PDAMgr;
class PDAPage : public Page {
public:
static PDAPage create(const Common::String &pageName, PDAMgr &pdaMgr);
private:
PDAPage(const Common::String &name) { _name = name; }
PDAPage(const Common::String& name, PinkEngine* vm);
};
} // End of namespace Pink

View File

@ -95,17 +95,14 @@ void PDAMgr::execute(const Command &command) {
}
}
void PDAMgr::goToPage(const Common::String &pageName) {
void PDAMgr::goToPage(const Common::String pageName) {
if (_page && !_page->getName().compareToIgnoreCase(pageName))
return;
loadGlobal();
PDAPage *newPage = new PDAPage(PDAPage::create(pageName, *this));
delete _page;
_page = newPage;
_page->init();
_page = new PDAPage(pageName, getGame());
_previousPages.push(_page->getName());
@ -188,8 +185,8 @@ void PDAMgr::loadGlobal() {
if (_globalPage)
return;
_globalPage = new PDAPage(PDAPage::create("GLOBAL", *this));
_globalPage->init();
delete _globalPage;
_globalPage = new PDAPage("GLOBAL", getGame());
}
void PDAMgr::initPerilButtons() {

View File

@ -45,7 +45,7 @@ public:
void saveState(Archive &archive);
void execute(const Command &command);
void goToPage(const Common::String &pageName);
void goToPage(const Common::String pageName);
void update() { _cursorMgr.update(); }