瀏覽代碼

Add a safety check for `CowData::_unref()`, for when something tries to add elements during destruction.

Lukas Tenbrink 3 月之前
父節點
當前提交
d2d57849de
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      core/templates/cowdata.h

+ 6 - 0
core/templates/cowdata.h

@@ -282,6 +282,12 @@ void CowData<T>::_unref() {
 
 	// Free memory.
 	Memory::free_static((uint8_t *)prev_ptr - DATA_OFFSET, false);
+
+#ifdef DEBUG_ENABLED
+	// If any destructors access us through pointers, it is a bug.
+	// We can't really test for that, but we can at least check no items have been added.
+	ERR_FAIL_COND_MSG(_ptr != nullptr, "Internal bug, please report: CowData was modified during destruction.");
+#endif
 }
 
 template <typename T>