Skip to content

Commit d120f2c

Browse files
committed
fix #486: Clear pending questions when a script stops
1 parent cc2f104 commit d120f2c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/blocks/sensingblocks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ void SensingBlocks::registerBlocks(IEngine *engine)
9595
engine->questionAnswered().connect(&onAnswer);
9696
}
9797

98+
void SensingBlocks::onInit(IEngine *engine)
99+
{
100+
engine->threadAboutToStop().connect([engine](VirtualMachine *thread) {
101+
if (!m_questionList.empty()) {
102+
// Abort the question of this thread if it's currently being displayed
103+
if (m_questionList.front()->vm == thread) {
104+
thread->target()->setBubbleText("");
105+
engine->questionAborted()();
106+
}
107+
108+
m_questionList
109+
.erase(std::remove_if(m_questionList.begin(), m_questionList.end(), [thread](const std::unique_ptr<Question> &question) { return question->vm == thread; }), m_questionList.end());
110+
}
111+
});
112+
}
113+
98114
void SensingBlocks::compileTouchingObject(Compiler *compiler)
99115
{
100116
Input *input = compiler->input(TOUCHINGOBJECTMENU);

src/blocks/sensingblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class SensingBlocks : public IBlockSection
6060
std::string name() const override;
6161

6262
void registerBlocks(IEngine *engine) override;
63+
void onInit(IEngine *engine) override;
6364

6465
static void compileTouchingObject(Compiler *compiler);
6566
static void compileTouchingColor(Compiler *compiler);

0 commit comments

Comments
 (0)