mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Core: Isolate Ref forward declare logic
This commit is contained in:
parent
2303ce843a
commit
d9ef361d12
2 changed files with 9 additions and 5 deletions
|
|
@ -36,10 +36,9 @@
|
||||||
#include "core/templates/rb_set.h"
|
#include "core/templates/rb_set.h"
|
||||||
|
|
||||||
#include "modules/modules_enabled.gen.h" // For regex.
|
#include "modules/modules_enabled.gen.h" // For regex.
|
||||||
|
|
||||||
#ifdef MODULE_REGEX_ENABLED
|
#ifdef MODULE_REGEX_ENABLED
|
||||||
#include "modules/regex/regex.h"
|
#include "modules/regex/regex.h"
|
||||||
#else
|
|
||||||
class RegEx : public RefCounted {};
|
|
||||||
#endif // MODULE_REGEX_ENABLED
|
#endif // MODULE_REGEX_ENABLED
|
||||||
|
|
||||||
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
|
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
|
||||||
|
|
|
||||||
|
|
@ -180,10 +180,15 @@ public:
|
||||||
// do a lot of referencing on references and stuff
|
// do a lot of referencing on references and stuff
|
||||||
// mutexes will avoid more crashes?
|
// mutexes will avoid more crashes?
|
||||||
|
|
||||||
if (reference && reference->unreference()) {
|
if (reference) {
|
||||||
memdelete(reference);
|
// NOTE: `reinterpret_cast` is "safe" here because we know `T` has simple linear
|
||||||
|
// inheritance to `RefCounted`. This guarantees that `T * == `RefCounted *`, which
|
||||||
|
// allows us to declare `Ref<T>` with forward declared `T` types.
|
||||||
|
if (reinterpret_cast<RefCounted *>(reference)->unreference()) {
|
||||||
|
memdelete(reinterpret_cast<RefCounted *>(reference));
|
||||||
|
}
|
||||||
|
reference = nullptr;
|
||||||
}
|
}
|
||||||
reference = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... VarArgs>
|
template <typename... VarArgs>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue