2
0
Эх сурвалжийг харах

added printCreationStackTrace to Functors in __dev__

Darren Ranalli 18 жил өмнө
parent
commit
1892796e2a

+ 11 - 0
direct/src/showbase/PythonUtil.py

@@ -2907,8 +2907,11 @@ def recordCreationStack(cls):
         return self.__moved_init__(*args, **kArgs)
     def getCreationStackTrace(self):
         return self._creationStackTrace
+    def printCreationStackTrace(self):
+        print self._creationStackTrace
     cls.__init__ = __recordCreationStack_init__
     cls.getCreationStackTrace = getCreationStackTrace
+    cls.printCreationStackTrace = printCreationStackTrace
     return cls
 
 
@@ -3204,6 +3207,14 @@ def logBlock(id, msg):
     print str(msg)
     print '/LOGBLOCK(%03d) >>' % id
         
+# __dev__ is not defined at import time, call this after it's defined
+def recordFunctorCreationStacks():
+    global Functor
+    if __dev__:
+        if not hasattr(Functor, '_functorCreationStacksRecorded'):
+            Functor = recordCreationStack(Functor)
+            Functor._functorCreationStacksRecorded = True
+
 import __builtin__
 __builtin__.Functor = Functor
 __builtin__.Stack = Stack

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

@@ -20,6 +20,7 @@ from direct.task.TaskManagerGlobal import *
 from JobManagerGlobal import *
 from EventManagerGlobal import *
 from PythonUtil import *
+from direct.showbase import PythonUtil
 from direct.particles.ParticleManagerGlobal import *
 from PhysicsManagerGlobal import *
 #from direct.interval.IntervalManager import ivalMgr
@@ -317,6 +318,9 @@ class ShowBase(DirectObject.DirectObject):
 
         ShowBase.notify.info('__dev__ == %s' % __dev__)
 
+        # set up recording of Functor creation stacks in __dev__
+        PythonUtil.recordFunctorCreationStacks()
+        
         if __dev__ or self.config.GetBool('want-e3-hacks', False):
             if self.config.GetBool('track-gui-items', True):
                 # dict of guiId to gui item, for tracking down leaks