From c8fe66092bc5741a9b47a41172597c778aac2322 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 29 Dec 2019 21:42:41 -0500 Subject: [PATCH] Attempts to correct insertion logic (and mostly bypasses it). --- Machines/Atari/ST/Video.hpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Machines/Atari/ST/Video.hpp b/Machines/Atari/ST/Video.hpp index ef61a5609..4f9f06dd5 100644 --- a/Machines/Atari/ST/Video.hpp +++ b/Machines/Atari/ST/Video.hpp @@ -269,17 +269,22 @@ class Video { return; } - // Otherwise enqueue, having subtracted the delay for any preceding events, - // and subtracting from the subsequent, if any. - auto insertion_point = pending_events_.begin(); - while(insertion_point != pending_events_.end() && insertion_point->delay > delay) { - delay -= insertion_point->delay; - ++insertion_point; + if(!pending_events_.empty()) { + // Otherwise enqueue, having subtracted the delay for any preceding events, + // and subtracting from the subsequent, if any. + auto insertion_point = pending_events_.begin(); + while(insertion_point != pending_events_.end() && insertion_point->delay < delay) { + delay -= insertion_point->delay; + ++insertion_point; + } + if(insertion_point != pending_events_.end()) { + insertion_point->delay -= delay; + } + + pending_events_.emplace(insertion_point, type, delay); + } else { + pending_events_.emplace_back(type, delay); } - if(insertion_point != pending_events_.end()) { - insertion_point->delay -= delay; - } - pending_events_.emplace(insertion_point, type, delay); } friend class ::VideoTester;