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

View File

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