diff --git a/Core/HW/Display.cpp b/Core/HW/Display.cpp index f21d442d33..419e02162d 100644 --- a/Core/HW/Display.cpp +++ b/Core/HW/Display.cpp @@ -250,15 +250,14 @@ void DisplayFireVblankEnd() { } void DisplayFireFlip() { - std::vector toCall = [] { - std::lock_guard guard(listenersLock); - return flipListeners; - }(); - // This is also the right time to calculate FPS. CalculateFPS(); - for (FlipListener cb : toCall) { + // Held across the calls, so that once __DisplayForgetFlip() returns (on a debugger connection's + // thread, say) its listener isn't running and won't be called again. A listener must not add or + // remove listeners. + std::lock_guard guard(listenersLock); + for (const FlipListener &cb : flipListeners) { cb.first(cb.second); } } @@ -281,7 +280,10 @@ void __DisplayForgetFlip(FlipCallback callback, void *userdata) { // This is called on game bootup. void DisplayHWInit() { - flipListeners.clear(); + { + std::lock_guard guard(listenersLock); + flipListeners.clear(); + } frameStartTicks = 0; numVBlanks = 0; isVblank = 0;