I did another test, this time looking at the memory usage reported by the windows task manager. This time when mines exploded but did not print to the command prompt the memory usage did not drop. But, as you say David, that’s not indicative of objects being deleted.
If I’m reading your post correctly, though, you’re telling me that the missing print statements from the del function means the objects are not being deleted.
Now I have to figure out why the clean up script I wrote works some of the time, but not all of the time.
Here is the init function from the mine class:
def __init__(self, cycle, pos, patternPos, gunStats):
self.cycle = cycle
self.gunStats = gunStats
self.root = self.cycle.assetLoader.loadModel(gunStats["Mine Model"]) # Loads and stores the model for the mine.
self.root.reparentTo(render)
self.root.setH(self.cycle.getH())
self.mode = "Move"
self.setPos(pos) # Sets the mine to the initial position.
self.patternPos = [float(patternPos[0]), float(patternPos[1])]
self.currentShield = self.gunStats["Shield Strength"] # Stores the current strength of the mine's shield.
self.team = self.cycle.team
self.track = self.cycle.track
self.timer = 0
self.explode = False
self.shieldCN = CollisionNode("MineShieldCN")
self.shieldCN.setPythonTag("owner", self)
self.shieldCS = CollisionSphere(0,0,0,1)
self.shieldCN.addSolid(self.shieldCS)
self.shieldCN.setIntoCollideMask(BitMask32.range(3,3))
self.shieldCN.setFromCollideMask(BitMask32.bit(2))
self.shieldCNP = self.root.attachNewNode(self.shieldCN)
#self.shieldCNP.show()
self.CN = CollisionNode("MineCN")
self.CS = CollisionSphere(0,0,0,self.gunStats["Blast Radius"])
self.CN.addSolid(self.CS)
self.CN.setIntoCollideMask(BitMask32.allOff())
self.CN.setFromCollideMask(BitMask32.bit(4))
self.CNP = self.root.attachNewNode(self.CN)
#self.CNP.show()
# Creates a collision sphere for the mine, turns off it's into mask, and sets the from Mask to 4,
# The collision node is parented to the graphic mine model.
self.CTrav = CollisionTraverser()
self.CHan = CollisionHandlerQueue()
self.CTrav.addCollider(self.CNP, self.CHan)
# Creates a traverser and queue handler to detect and deal with collisions.
taskMgr.add(self.runAI, "mineAI")
# Adds the update task to the task manager.
Here is the clean up script. It’s located within the runAI task that’s added at the end of the init function.
if(self.explode == True):
self.cycle.boomManager.addBoom(self.gunStats["Boom Model"], self.getPos(), self.gunStats["Blast Radius"], self.gunStats["Damage"])
self.mode = "Done"
self.shieldCN.clearPythonTag("owner")
self.root.removeNode()
self.shieldCNP.removeNode()
self.CNP.removeNode()
return task.done
It’s an almost exact copy of a clean up script I’m using in another weapon type, and that weapon type cleans up without fail every time. For the life of me, I just can’t discern what I’m missing.
Oh, and for your info, the variable that references the class instance directly is deleted when the mine layer detects that the mode has changed to “Done”. I tested and confirmed that part, so I know it’s working properly.
If you see something I’m missing, please let me know.