Skip to content

Commit b47e9ac

Browse files
committed
fix playlayer leaks
1 parent 61975ad commit b47e9ac

4 files changed

Lines changed: 24 additions & 44 deletions

File tree

src/hooks/obstructive/Math.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ class $modify(MathPlayLayer, PlayLayer) {
4747
nextQuiz();
4848
};
4949

50-
void onQuit() {
51-
cue::resetNode(m_fields->currentMath);
52-
PlayLayer::onQuit();
53-
};
54-
5550
void nextQuiz() {
5651
log::trace("scheduling math quiz");
5752

@@ -67,15 +62,13 @@ class $modify(MathPlayLayer, PlayLayer) {
6762

6863
if (auto quiz = MathQuiz::create()) {
6964
// handle correct/wrong answer
70-
quiz->setCallback([self = WeakRef(this), math = WeakRef(quiz)](bool correct) {
71-
if (auto s = self.lock()) {
72-
if (!correct) s->resetLevelFromStart();
73-
s->nextQuiz();
65+
quiz->setCallback([this, quiz](bool correct) {
66+
if (!correct) resetLevelFromStart();
67+
nextQuiz();
7468

75-
cursor::hide();
69+
cursor::hide();
7670

77-
if (auto quiz = math.lock()) quiz->removeFromParent();
78-
};
71+
if (quiz) quiz->removeFromParent();
7972
});
8073

8174
m_uiLayer->addChild(quiz, 99);

src/hooks/obstructive/Spam.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ class $modify(SpamPlayLayer, PlayLayer) {
4747
nextSpam();
4848
};
4949

50-
void onQuit() {
51-
cue::resetNode(m_fields->currentSpam);
52-
PlayLayer::onQuit();
53-
};
54-
5550
void destroyPlayer(PlayerObject* player, GameObject* object) {
5651
PlayLayer::destroyPlayer(player, object);
5752

@@ -78,15 +73,13 @@ class $modify(SpamPlayLayer, PlayLayer) {
7873
auto f = m_fields.self();
7974

8075
// handle correct/wrong answer
81-
spam->setCallback([self = WeakRef(this), challenge = WeakRef(spam)](bool success) {
82-
if (auto s = self.lock()) {
83-
if (!success) s->resetLevelFromStart();
84-
s->nextSpam();
76+
spam->setCallback([this, spam](bool success) {
77+
if (!success) resetLevelFromStart();
78+
nextSpam();
8579

86-
cursor::hide();
80+
cursor::hide();
8781

88-
if (auto spam = challenge.lock()) spam->removeFromParent();
89-
};
82+
if (spam) spam->removeFromParent();
9083
});
9184

9285
m_uiLayer->addChild(spam, 99);

src/hooks/obstructive/WhackAFace.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ class $modify(WhackAFacePlayLayer, PlayLayer) {
9696
if (auto whack = WhackButton::create()) {
9797
auto const winSize = m_uiLayer->getScaledContentSize();
9898

99-
whack->setCallback([self = WeakRef(this), whackButton = WeakRef(whack)](bool success) {
100-
if (auto whack = whackButton.lock()) {
101-
if (!success) {
102-
if (auto s = self.lock()) s->resetLevelFromStart();
103-
};
104-
105-
cursor::show();
106-
whack->removeFromParent();
107-
};
99+
whack->setCallback([this, whack](bool success) {
100+
if (!success) resetLevelFromStart();
101+
102+
cursor::show();
103+
whack->removeFromParent();
108104
});
109105
whack->setPosition(CCPoint{winSize.width * rng::get(0.75f, 0.25f), winSize.height * rng::get(0.75f, 0.25f)} / 2.f);
110106

src/util/ui/src/WhackButton.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ void WhackButton::reload() {
5858
s_severities.at(diff),
5959
1.f,
6060
m_impl->getButtonColor(diff)),
61-
[self = WeakRef(this)](auto) {
62-
if (auto s = self.lock()) {
63-
s->m_impl->inputCount += 1;
64-
sfx::play("chestClick.ogg");
65-
66-
if (s->m_impl->inputCount >= s->m_impl->inputTarget) {
67-
s->setSuccess(true);
68-
s->unscheduleUpdate();
69-
} else {
70-
s->reload();
71-
};
61+
[this](auto) {
62+
m_impl->inputCount += 1;
63+
sfx::play("chestClick.ogg");
64+
65+
if (m_impl->inputCount >= m_impl->inputTarget) {
66+
setSuccess(true);
67+
unscheduleUpdate();
68+
} else {
69+
reload();
7270
};
7371
});
7472
m_impl->button->setID("whackable-btn");

0 commit comments

Comments
 (0)