only record creation stack in dev

This commit is contained in:
Darren Ranalli 2007-05-14 23:11:17 +00:00
parent bc11859271
commit f191acace1
2 changed files with 20 additions and 13 deletions

View File

@ -13,8 +13,11 @@ from direct.showbase import DirectObject
from direct.task import Task from direct.task import Task
from direct.showbase import ShowBase from direct.showbase import ShowBase
from direct.showbase.PythonUtil import recordCreationStack from direct.showbase.PythonUtil import recordCreationStack
from pandac.PandaModules import PStatCollector
import string, types import string, types
guiObjectCollector = PStatCollector("Client::GuiObjects")
""" """
Base class for all Direct Gui items. Handles composite widgets and Base class for all Direct Gui items. Handles composite widgets and
command line argument parsing. command line argument parsing.
@ -648,9 +651,9 @@ def toggleGuiGridSnap():
def setGuiGridSpacing(spacing): def setGuiGridSpacing(spacing):
DirectGuiWidget.gridSpacing = spacing DirectGuiWidget.gridSpacing = spacing
if __debug__: if __dev__:
# this will help track down who created DirectGui objects # this will help track down the code that created DirectGui objects
# call obj.getCreationStackTrace() to figure out who created it # call obj.getCreationStackTrace() to figure out what code created it
DirectGuiBase = recordCreationStack(DirectGuiBase) DirectGuiBase = recordCreationStack(DirectGuiBase)
class DirectGuiWidget(DirectGuiBase, NodePath): class DirectGuiWidget(DirectGuiBase, NodePath):
@ -723,6 +726,8 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
self.guiItem.setId(self['guiId']) self.guiItem.setId(self['guiId'])
self.guiId = self.guiItem.getId() self.guiId = self.guiItem.getId()
if __dev__: if __dev__:
guiObjectCollector.addLevel(1)
guiObjectCollector.flushLevel()
# track gui items by guiId for tracking down leaks # track gui items by guiId for tracking down leaks
if hasattr(base, 'guiItems'): if hasattr(base, 'guiItems'):
if self.guiId in base.guiItems: if self.guiId in base.guiItems:
@ -1020,7 +1025,10 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
self.updateFrameStyle() self.updateFrameStyle()
def destroy(self): def destroy(self):
if hasattr(self, "frameStyle"):
if __dev__: if __dev__:
guiObjectCollector.subLevel(1)
guiObjectCollector.flushLevel()
if hasattr(base, 'guiItems'): if hasattr(base, 'guiItems'):
if self.guiId in base.guiItems: if self.guiId in base.guiItems:
del base.guiItems[self.guiId] del base.guiItems[self.guiId]
@ -1029,7 +1037,6 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
'DirectGuiWidget.destroy(): ' 'DirectGuiWidget.destroy(): '
'gui item %s not in base.guiItems' % 'gui item %s not in base.guiItems' %
self.guiId) self.guiId)
if hasattr(self, "frameStyle"):
# Destroy children # Destroy children
for child in self.getChildrenAsList(): for child in self.getChildrenAsList():
childGui = self.guiDict.get(child.getName()) childGui = self.guiDict.get(child.getName())

View File

@ -76,7 +76,7 @@ class Task:
debugTaskTraceback = 0 # base.config.GetBool('debug-task-traceback', 0) debugTaskTraceback = 0 # base.config.GetBool('debug-task-traceback', 0)
count = 0 count = 0
def __init__(self, callback, priority = 0): def __init__(self, callback, priority = 0):
if __debug__: if __dev__:
if self.debugTaskTraceback: if self.debugTaskTraceback:
self.debugInitTraceback = StackTrace("Task "+str(callback), 1, 10) self.debugInitTraceback = StackTrace("Task "+str(callback), 1, 10)
# Unique ID for each task # Unique ID for each task