diff --git a/panda/src/cull/cullStateLookup.cxx b/panda/src/cull/cullStateLookup.cxx index 98a73e5383..f5982fb06f 100644 --- a/panda/src/cull/cullStateLookup.cxx +++ b/panda/src/cull/cullStateLookup.cxx @@ -178,9 +178,18 @@ clean_out_old_nodes() { while (csi != _cull_states.end()) { ++csnext; + Node *node = (*csi).first; CullState *cs = (*csi).second; - if (!cs->has_bin() && cs->is_empty() && - cs->get_empty_frames_count() > 100) { + + if (node->get_ref_count() == 1) { + // If we've got the only outstanding pointer to this node, + // the node was deleted. Drop our reference. + _cull_states.erase(csi); + + } else if (!cs->has_bin() && cs->is_empty() && + cs->get_empty_frames_count() > 100) { + // If the CullState doesn't even have any nodes, delete it after + // 100 frames have elapsed. _cull_states.erase(csi); } csi = csnext;