From d2d57849de3cc489484b4e6a35332d56f6044641 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Tue, 27 May 2025 12:48:31 +0200 Subject: [PATCH] Add a safety check for `CowData::_unref()`, for when something tries to add elements during destruction. --- core/templates/cowdata.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h index ac51feb0bb..566a01c293 100644 --- a/core/templates/cowdata.h +++ b/core/templates/cowdata.h @@ -282,6 +282,12 @@ void CowData::_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