fix missing cleanup and null checks for various singletons

This commit is contained in:
rune-scape 2024-06-18 00:30:20 -07:00
parent 8c70c18132
commit 6adcb1373a
6 changed files with 18 additions and 4 deletions

View File

@ -3537,7 +3537,7 @@ void EditorNode::add_extension_editor_plugin(const StringName &p_class_name) {
void EditorNode::remove_extension_editor_plugin(const StringName &p_class_name) { void EditorNode::remove_extension_editor_plugin(const StringName &p_class_name) {
// If we're exiting, the editor plugins will get cleaned up anyway, so don't do anything. // If we're exiting, the editor plugins will get cleaned up anyway, so don't do anything.
if (singleton->exiting) { if (!singleton || singleton->exiting) {
return; return;
} }

View File

@ -8431,6 +8431,7 @@ Node3DEditor::Node3DEditor() {
VBoxContainer *vbc = this; VBoxContainer *vbc = this;
custom_camera = nullptr; custom_camera = nullptr;
ERR_FAIL_COND_MSG(singleton != nullptr, "A Node3DEditor singleton already exists.");
singleton = this; singleton = this;
editor_selection = EditorNode::get_singleton()->get_editor_selection(); editor_selection = EditorNode::get_singleton()->get_editor_selection();
editor_selection->add_editor_plugin(this); editor_selection->add_editor_plugin(this);
@ -9060,6 +9061,7 @@ void fragment() {
clear(); // Make sure values are initialized. Will call _snap_update() for us. clear(); // Make sure values are initialized. Will call _snap_update() for us.
} }
Node3DEditor::~Node3DEditor() { Node3DEditor::~Node3DEditor() {
singleton = nullptr;
memdelete(preview_node); memdelete(preview_node);
if (preview_sun_dangling && preview_sun) { if (preview_sun_dangling && preview_sun) {
memdelete(preview_sun); memdelete(preview_sun);

View File

@ -545,8 +545,13 @@ public:
virtual void set_debug_redraw(bool p_enabled, double p_time, const Color &p_color) = 0; virtual void set_debug_redraw(bool p_enabled, double p_time, const Color &p_color) = 0;
RendererCanvasRender() { singleton = this; } RendererCanvasRender() {
virtual ~RendererCanvasRender() {} ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCanvasRender singleton already exists.");
singleton = this;
}
virtual ~RendererCanvasRender() {
singleton = nullptr;
}
}; };
#endif // RENDERER_CANVAS_RENDER_H #endif // RENDERER_CANVAS_RENDER_H

View File

@ -47,6 +47,7 @@ bool RendererCompositor::is_xr_enabled() const {
} }
RendererCompositor::RendererCompositor() { RendererCompositor::RendererCompositor() {
ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCompositor singleton already exists.");
singleton = this; singleton = this;
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
@ -57,3 +58,7 @@ RendererCompositor::RendererCompositor() {
} }
#endif // _3D_DISABLED #endif // _3D_DISABLED
} }
RendererCompositor::~RendererCompositor() {
singleton = nullptr;
}

View File

@ -110,7 +110,7 @@ public:
static RendererCompositor *get_singleton() { return singleton; } static RendererCompositor *get_singleton() { return singleton; }
RendererCompositor(); RendererCompositor();
virtual ~RendererCompositor() {} virtual ~RendererCompositor();
}; };
#endif // RENDERER_COMPOSITOR_H #endif // RENDERER_COMPOSITOR_H

View File

@ -299,6 +299,7 @@ RendererCompositorRD::RendererCompositorRD() {
} }
} }
ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCompositorRD singleton already exists.");
singleton = this; singleton = this;
utilities = memnew(RendererRD::Utilities); utilities = memnew(RendererRD::Utilities);
@ -330,6 +331,7 @@ RendererCompositorRD::RendererCompositorRD() {
} }
RendererCompositorRD::~RendererCompositorRD() { RendererCompositorRD::~RendererCompositorRD() {
singleton = nullptr;
memdelete(uniform_set_cache); memdelete(uniform_set_cache);
memdelete(framebuffer_cache); memdelete(framebuffer_cache);
ShaderRD::set_shader_cache_dir(String()); ShaderRD::set_shader_cache_dir(String());