Skip to content

Commit db4b02c

Browse files
committed
Fix replacement of event queue background.
This was discovered when EventQueue::background was called with a nullptr. It crashes the software as it tries to call into a nullptr.
1 parent f89655f commit db4b02c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

events/source/EventQueue.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,18 @@ int EventQueue::time_left(int id)
8383

8484
void EventQueue::background(Callback<void(int)> update)
8585
{
86+
// Start by setting the background callback to nullptr
87+
// as equeue_background calls the existing handler with a timeout
88+
// of -1 to indicate to the callback that the tineout process is
89+
// not further required.
90+
// Updating _update before would prevent calling into the
91+
// old callback as the callbacks share the same memory locations.
92+
equeue_background(&_equeue, 0, 0);
93+
8694
_update = update;
8795

8896
if (_update) {
8997
equeue_background(&_equeue, &Callback<void(int)>::thunk, &_update);
90-
} else {
91-
equeue_background(&_equeue, 0, 0);
9298
}
9399
}
94100

0 commit comments

Comments
 (0)