From 5cd64e3a4d5192ad1f56592153f1aeeaa67348b4 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 2 Dec 2003 21:48:26 +0000 Subject: [PATCH] fix crash after switching avatars --- direct/src/distributed/ClientRepository.py | 9 +++++++-- direct/src/distributed/RelatedObjectMgr.py | 23 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index b1548a7941..a5860528ac 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -37,8 +37,13 @@ class ClientRepository(ConnectionRepository.ConnectionRepository): # other. self.relatedObjectMgr = RelatedObjectMgr.RelatedObjectMgr(self) - def delete(self): - self.relatedObjectMgr.destroy() + def abruptCleanup(self): + """ + Call this method to clean up any pending hooks or tasks on + distributed objects, but leave the ClientRepository in a sane + state for creating more distributed objects. + """ + self.relatedObjectMgr.abortAllRequests() def setServerDelta(self, delta): """ diff --git a/direct/src/distributed/RelatedObjectMgr.py b/direct/src/distributed/RelatedObjectMgr.py index c911599372..2bdeb8c04e 100644 --- a/direct/src/distributed/RelatedObjectMgr.py +++ b/direct/src/distributed/RelatedObjectMgr.py @@ -36,9 +36,9 @@ class RelatedObjectMgr(DirectObject.DirectObject): self.pendingObjects = {} def destroy(self): + self.abortAllRequests() del self.cr del self.pendingObjects - self.ignoreAll() def requestObjects(self, doIdList, allCallback = None, eachCallback = None, timeout = None, timeoutCallback = None): @@ -148,6 +148,27 @@ class RelatedObjectMgr(DirectObject.DirectObject): taskMgr.remove(doLaterName) self.__removePending(tuple, doIdsPending) + def abortAllRequests(self): + """ + Call this method to abruptly abort all pending requests, but + leave the RelatedObjectMgr in a state for accepting more + requests. + """ + + # Stop listening for all events. + self.ignoreAll() + + # Iterate through all the pendingObjects and stop any pending + # tasks. + for pendingList in self.pendingObjects.values(): + for tuple in pendingList: + allCallback, eachCallback, timeoutCallback, doIdsPending, doIdList, doLaterName = tuple + if doLaterName: + taskMgr.remove(doLaterName) + + self.pendingObjects = {} + + def __timeoutExpired(self, tuple): allCallback, eachCallback, timeoutCallback, doIdsPending, doIdList, doLaterName = tuple assert(self.notify.debug("timeout expired for %s (remaining: %s)" % (doIdList, doIdsPending)))