From e12db30345fa3c606096b24e038e9bb9c2be3b5d Mon Sep 17 00:00:00 2001 From: zeyus Date: Thu, 29 Aug 2024 14:40:25 +0200 Subject: [PATCH] Avoid infinite loop when function schedules callOnFlip for next frame --- psychopy/visual/window.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/psychopy/visual/window.py b/psychopy/visual/window.py index d0498dea74..d00b075aa8 100644 --- a/psychopy/visual/window.py +++ b/psychopy/visual/window.py @@ -1320,10 +1320,12 @@ def flip(self, clearBuffer=True): self._frameTime = now = logging.defaultClock.getTime() self._frameTimes.append(self._frameTime) - # run other functions immediately after flip completes - for callEntry in self._toCall: - callEntry['function'](*callEntry['args'], **callEntry['kwargs']) - del self._toCall[:] + # run scheduled functions immediately after flip completes + n_items = len(self._toCall) + for i in range(n_items): + self._toCall[i]['function'](*self._toCall[i]['args'], **self._toCall[i]['kwargs']) + # leave newly scheduled functions for next flip + del self._toCall[:n_items] # do bookkeeping if self.recordFrameIntervals: