Browse Source

track-gui-items and cTrav stack

Darren Ranalli 19 years ago
parent
commit
a8697a4594
2 changed files with 36 additions and 0 deletions
  1. 21 0
      direct/src/gui/DirectGuiBase.py
  2. 15 0
      direct/src/showbase/ShowBase.py

+ 21 - 0
direct/src/gui/DirectGuiBase.py

@@ -626,6 +626,10 @@ class DirectGuiBase(DirectObject.DirectObject):
         """
         # Need to tack on gui item specific id
         gEvent = event + self.guiId
+        if base.config.GetBool('debug-directgui-msgs', False):
+            from direct.showbase.PythonUtil import StackTrace
+            print gEvent
+            print StackTrace()
         self.accept(gEvent, command, extraArgs = extraArgs)
 
     def unbind(self, event):
@@ -711,6 +715,14 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
         if self['guiId']:
             self.guiItem.setId(self['guiId'])
         self.guiId = self.guiItem.getId()
+        if __dev__:
+            # track gui items by guiId for tracking down leaks
+            if hasattr(base, 'guiItems'):
+                if self.guiId in base.guiItems:
+                    base.notify.warning('duplicate guiId: %s (%s stomping %s)' %
+                                        (self.guiId, self,
+                                         base.guiItems[self.guiId]))
+                base.guiItems[self.guiId] = self
         # Attach button to parent and make that self
         if (parent == None):
             parent = aspect2d
@@ -996,6 +1008,15 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
         self.updateFrameStyle()
 
     def destroy(self):
+        if __dev__:
+            if hasattr(base, 'guiItems'):
+                if self in base.guiItems:
+                    del base.guiItems[self.guiId]
+                else:
+                    base.notify.warning(
+                        'DirectGuiWidget.destroy(): '
+                        'gui item %s not in base.guiItems' %
+                        self.guiId)
         if hasattr(self, "frameStyle"):
             # Destroy children
             for child in self.getChildrenAsList():

+ 15 - 0
direct/src/showbase/ShowBase.py

@@ -154,6 +154,7 @@ class ShowBase(DirectObject.DirectObject):
         self.shadowTrav = 0
         # in the collisionLoop task.
         self.cTrav = 0
+        self.cTravStack = Stack()
         # Ditto for an AppTraverser.
         self.appTrav = 0
 
@@ -247,6 +248,11 @@ class ShowBase(DirectObject.DirectObject):
 
         ShowBase.notify.info('__dev__ == %s' % __dev__)
 
+        if __dev__:
+            if self.config.GetBool('track-gui-items', True):
+                # dict of guiId to gui item, for tracking down leaks
+                self.guiItems = {}
+
         # Now hang a hook on the window-event from Panda.  This allows
         # us to detect when the user resizes, minimizes, or closes the
         # main window.
@@ -286,6 +292,15 @@ class ShowBase(DirectObject.DirectObject):
         # Start IGLOOP
         self.restart()
 
+    # add a collision traverser via pushCTrav and remove it via popCTrav
+    # that way the owner of the new cTrav doesn't need to hold onto the
+    # previous one in order to put it back
+    def pushCTrav(self, cTrav):
+        self.cTravStack.push(self.cTrav)
+        self.cTrav = cTrav
+    def popCTrav(self):
+        self.cTrav = self.cTravStack.pop()
+
     def printEnvDebugInfo(self):
         """
         Print some information about the environment that we are running