From 92b9f2e8da5b65bc48b8a4b71d97f1bb41d531ba Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Fri, 3 Sep 2004 16:57:02 +0000 Subject: [PATCH] Fixed doLater ordering problem on gc pass --- direct/src/task/Task.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 999e25da6e..c4b015eecf 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -14,7 +14,7 @@ import time import fnmatch import string import signal -from libheapq import heappush, heappop +from libheapq import heappush, heappop, heapify # MRM: Need to make internal task variables like time, name, index # more unique (less likely to have name clashes) @@ -305,6 +305,8 @@ class TaskManager: extendedExceptions = 0 pStatsTasks = 0 + doLaterCleanupCounter = 2000 + def __init__(self): self.running = 0 self.stepping = 0 @@ -366,6 +368,8 @@ class TaskManager: # been removed Warning: this creates an entirely new doLaterList. oldLen = len(self.__doLaterList) self.__doLaterList = filter(lambda task: not task.isRemoved(), self.__doLaterList) + # Re heapify to maintain ordering after filter + heapify(self.__doLaterList) newLen = len(self.__doLaterList) return oldLen - newLen @@ -395,7 +399,7 @@ class TaskManager: continue # Every nth pass, let's clean out the list of removed tasks # This is basically a mark and sweep garbage collection of doLaters - if ((task.frame % 1000) == 0): + if ((task.frame % self.doLaterCleanupCounter) == 0): numRemoved = self.__doLaterFilter() # TaskManager.notify.debug("filtered %s removed doLaters" % numRemoved) return cont