소스 검색

fix memory leak when rendering certain particle effects

David Rose 19 년 전
부모
커밋
686bff860f
3개의 변경된 파일27개의 추가작업 그리고 22개의 파일을 삭제
  1. 13 11
      panda/src/cull/cullBinBackToFront.cxx
  2. 13 11
      panda/src/cull/cullBinFrontToBack.cxx
  3. 1 0
      panda/src/cull/cullBinOcclusionTest.cxx

+ 13 - 11
panda/src/cull/cullBinBackToFront.cxx

@@ -63,18 +63,20 @@ void CullBinBackToFront::
 add_object(CullableObject *object, Thread *current_thread) {
 add_object(CullableObject *object, Thread *current_thread) {
   // Determine the center of the bounding volume.
   // Determine the center of the bounding volume.
   CPT(BoundingVolume) volume = object->_geom->get_bounds(current_thread);
   CPT(BoundingVolume) volume = object->_geom->get_bounds(current_thread);
-
-  if (!volume->is_empty()) {
-    const GeometricBoundingVolume *gbv;
-    DCAST_INTO_V(gbv, volume);
-    
-    LPoint3f center = gbv->get_approx_center();
-    nassertv(object->_modelview_transform != (const TransformState *)NULL);
-    center = center * object->_modelview_transform->get_mat();
-    
-    float distance = _gsg->compute_distance_to(center);
-    _objects.push_back(ObjectData(object, distance));
+  if (volume->is_empty()) {
+    delete object;
+    return;
   }
   }
+
+  const GeometricBoundingVolume *gbv;
+  DCAST_INTO_V(gbv, volume);
+  
+  LPoint3f center = gbv->get_approx_center();
+  nassertv(object->_modelview_transform != (const TransformState *)NULL);
+  center = center * object->_modelview_transform->get_mat();
+  
+  float distance = _gsg->compute_distance_to(center);
+  _objects.push_back(ObjectData(object, distance));
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 13 - 11
panda/src/cull/cullBinFrontToBack.cxx

@@ -63,18 +63,20 @@ void CullBinFrontToBack::
 add_object(CullableObject *object, Thread *current_thread) {
 add_object(CullableObject *object, Thread *current_thread) {
   // Determine the center of the bounding volume.
   // Determine the center of the bounding volume.
   CPT(BoundingVolume) volume = object->_geom->get_bounds();
   CPT(BoundingVolume) volume = object->_geom->get_bounds();
-
-  if (!volume->is_empty()) {
-    const GeometricBoundingVolume *gbv;
-    DCAST_INTO_V(gbv, volume);
-    
-    LPoint3f center = gbv->get_approx_center();
-    nassertv(object->_modelview_transform != (const TransformState *)NULL);
-    center = center * object->_modelview_transform->get_mat();
-    
-    float distance = _gsg->compute_distance_to(center);
-    _objects.push_back(ObjectData(object, distance));
+  if (volume->is_empty()) {
+    delete object;
+    return;
   }
   }
+
+  const GeometricBoundingVolume *gbv;
+  DCAST_INTO_V(gbv, volume);
+  
+  LPoint3f center = gbv->get_approx_center();
+  nassertv(object->_modelview_transform != (const TransformState *)NULL);
+  center = center * object->_modelview_transform->get_mat();
+  
+  float distance = _gsg->compute_distance_to(center);
+  _objects.push_back(ObjectData(object, distance));
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
panda/src/cull/cullBinOcclusionTest.cxx

@@ -121,6 +121,7 @@ add_object(CullableObject *object, Thread *current_thread) {
   // Determine the world-space bounding sphere for the object.
   // Determine the world-space bounding sphere for the object.
   CPT(BoundingVolume) volume = object->_geom->get_bounds();
   CPT(BoundingVolume) volume = object->_geom->get_bounds();
   if (volume->is_empty()) {
   if (volume->is_empty()) {
+    delete object;
     return;
     return;
   }
   }