Skip to content

Commit

Permalink
fix crashes caused by removing nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jan 19, 2024
1 parent 573198b commit 408d50b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/hooks/GJScoreCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class $modify(BIGJScoreCell, GJScoreCell) {
GJScoreCell::loadFromScore(b);

if(auto player = m_mainLayer->getChildByID("player-icon")) {
player->removeFromParent();

auto playerMenu = CCMenu::create();
playerMenu->setPosition(player->getPosition());

m_mainLayer->removeChild(player);
m_mainLayer->addChild(playerMenu);

auto container = CCNode::create();
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/ProfilePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class $modify(BIProfilePage, ProfilePage) {
} else {
if(auto playerStats = m_mainLayer->getChildByID("stats-menu")) {
if(auto starsIcon = playerStats->getChildByID("stars-icon")) {
BetterInfo::replaceWithButton(starsIcon, this, menu_selector(BIProfilePage::onProfilePageStar));
m_buttons->addObject(BetterInfo::replaceWithButton(starsIcon, this, menu_selector(BIProfilePage::onProfilePageStar)));
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ bool BetterInfo::isSprite(CCSprite* sprite, const char* name) {
return cache->getTexture() == sprite->getTexture() && cache->getRect() == sprite->getTextureRect();
}

void BetterInfo::replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_MenuHandler handler) {
CCMenuItemSpriteExtra* BetterInfo::replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_MenuHandler handler) {

auto parent = node->getParent();

Expand All @@ -622,6 +622,7 @@ void BetterInfo::replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_Menu
);
button->setLayoutOptions(node->getLayoutOptions());
button->setZOrder(node->getZOrder());
button->setID(node->getID());

parent->getChildren()->insertObject(button, idx);
parent->updateLayout();
Expand All @@ -632,6 +633,8 @@ void BetterInfo::replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_Menu
button->onEnter();
button->onEnterTransitionDidFinish();
}

return button;
}

UnlockType BetterInfo::iconTypeToUnlockType(IconType type)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace BetterInfo {
bool isHoveringNode(CCNode* target);

bool isSprite(CCSprite* sprite, const char* name);
void replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_MenuHandler handler);
CCMenuItemSpriteExtra* replaceWithButton(CCNode* node, CCNode* self, cocos2d::SEL_MenuHandler handler);

UnlockType iconTypeToUnlockType(IconType type);
}

0 comments on commit 408d50b

Please sign in to comment.