From 5168c006ef7bab5b876250543545b34bc53b30a6 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 15 Jan 2026 04:14:59 -0500 Subject: [PATCH] prevent calcTimestamps from hanging when the virtual tempo is 0 or infinity --- src/engine/song.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/engine/song.cpp b/src/engine/song.cpp index b1a59709f..b65145550 100644 --- a/src/engine/song.cpp +++ b/src/engine/song.cpp @@ -351,6 +351,12 @@ void DivSubSong::calcTimestamps(int chans, std::vector& groove // MAKE IT WORK while (!endOfSong) { + // if the virtual tempo nominator is zero, the song will go on forever. + if (curVirtualTempoN<1) { + ts.totalTime.seconds=INT_MAX; + break; + } + // heuristic int advance=(curVirtualTempoD*ticks)/curVirtualTempoN; for (int i=0; i& groove // run virtual tempo tempoAccum+=curVirtualTempoN*advance; while (tempoAccum>=curVirtualTempoD) { - int ticksToRun=tempoAccum/curVirtualTempoD; - tempoAccum%=curVirtualTempoD; + int ticksToRun=tempoAccum/MAX(1,curVirtualTempoD); + tempoAccum%=MAX(1,curVirtualTempoD); // tick counter ticks-=ticksToRun; if (ticks<0) { // if ticks is negative, we must call ticks back - tempoAccum+=-ticks*curVirtualTempoD; + tempoAccum+=-ticks*MAX(1,curVirtualTempoD); } if (ticks<=0) { if (shallStopSched) {