Browse Source

pgraph: Fix CullableObject incorrect use of memory usage tracking

rdb 3 months ago
parent
commit
b6dc37cfb0

+ 5 - 1
panda/src/pgraph/cullResult.I

@@ -43,7 +43,11 @@ alloc_object(CullableObject &&object) {
   if (page->_size >= page->_capacity) {
     page = new_page();
   }
-  return new (page->_memory + sizeof(CullableObject) * (page->_size++)) CullableObject(std::move(object));
+  void *ptr = page->_memory + sizeof(CullableObject) * (page->_size++);
+#ifdef DO_MEMORY_USAGE
+  //memory_hook->mark_pointer(ptr, sizeof(CullableObject), nullptr);
+#endif
+  return new (ptr) CullableObject(std::move(object));
 }
 
 /**

+ 3 - 0
panda/src/pgraph/cullResult.cxx

@@ -385,6 +385,9 @@ delete_page(AllocationPage *page) {
   size_t size = std::exchange(page->_size, 0);
   for (size_t i = 0; i < size; ++i) {
     ((CullableObject *)page->_memory)[i].~CullableObject();
+#ifdef DO_MEMORY_USAGE
+    //MemoryUsage::remove_void_pointer(&((CullableObject *)page->_memory)[i]);
+#endif
   }
   AllocationPage *next = page->_next;
   if (next != nullptr) {

+ 0 - 16
panda/src/pgraph/cullableObject.I

@@ -11,16 +11,6 @@
  * @date 2002-03-04
  */
 
-/**
- * Creates an empty CullableObject whose pointers can be filled in later.
- */
-INLINE CullableObject::
-CullableObject() {
-#ifdef DO_MEMORY_USAGE
-  MemoryUsage::record_pointer(this, get_class_type());
-#endif
-}
-
 /**
  * Creates a CullableObject based the indicated geom, with the indicated
  * render state and transform.
@@ -32,9 +22,6 @@ CullableObject(CPT(Geom) geom, CPT(RenderState) state,
   _state(std::move(state)),
   _internal_transform(std::move(internal_transform))
 {
-#ifdef DO_MEMORY_USAGE
-  MemoryUsage::record_pointer(this, get_class_type());
-#endif
 }
 
 /**
@@ -47,9 +34,6 @@ CullableObject(const CullableObject &copy) :
   _state(copy._state),
   _internal_transform(copy._internal_transform)
 {
-#ifdef DO_MEMORY_USAGE
-  MemoryUsage::record_pointer(this, get_class_type());
-#endif
 }
 
 /**

+ 1 - 1
panda/src/pgraph/cullableObject.h

@@ -40,7 +40,7 @@ class GeomMunger;
  */
 class EXPCL_PANDA_PGRAPH CullableObject {
 public:
-  INLINE CullableObject();
+  INLINE CullableObject() = default;
   INLINE CullableObject(CPT(Geom) geom, CPT(RenderState) state,
                         CPT(TransformState) internal_transform);