summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrune-scape <spartacrafter@gmail.com>2024-06-18 00:30:20 -0700
committerrune-scape <spartacrafter@gmail.com>2024-06-18 01:05:30 -0700
commit6adcb1373a78cc208c86b66f687c30051ff39bd6 (patch)
tree0fb07753397301aa4f850abfffc0a74abc76c115
parent8c70c18132441d11a88dd96b462d89d8eba4c2f5 (diff)
downloadredot-engine-6adcb1373a78cc208c86b66f687c30051ff39bd6.tar.gz
fix missing cleanup and null checks for various singletons
-rw-r--r--editor/editor_node.cpp2
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp2
-rw-r--r--servers/rendering/renderer_canvas_render.h9
-rw-r--r--servers/rendering/renderer_compositor.cpp5
-rw-r--r--servers/rendering/renderer_compositor.h2
-rw-r--r--servers/rendering/renderer_rd/renderer_compositor_rd.cpp2
6 files changed, 18 insertions, 4 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index d5e1242406..dd7024d964 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -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) {
// 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;
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 753b1971f4..4c8202916b 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -8431,6 +8431,7 @@ Node3DEditor::Node3DEditor() {
VBoxContainer *vbc = this;
custom_camera = nullptr;
+ ERR_FAIL_COND_MSG(singleton != nullptr, "A Node3DEditor singleton already exists.");
singleton = this;
editor_selection = EditorNode::get_singleton()->get_editor_selection();
editor_selection->add_editor_plugin(this);
@@ -9060,6 +9061,7 @@ void fragment() {
clear(); // Make sure values are initialized. Will call _snap_update() for us.
}
Node3DEditor::~Node3DEditor() {
+ singleton = nullptr;
memdelete(preview_node);
if (preview_sun_dangling && preview_sun) {
memdelete(preview_sun);
diff --git a/servers/rendering/renderer_canvas_render.h b/servers/rendering/renderer_canvas_render.h
index 4a56548932..cb8180f989 100644
--- a/servers/rendering/renderer_canvas_render.h
+++ b/servers/rendering/renderer_canvas_render.h
@@ -545,8 +545,13 @@ public:
virtual void set_debug_redraw(bool p_enabled, double p_time, const Color &p_color) = 0;
- RendererCanvasRender() { singleton = this; }
- virtual ~RendererCanvasRender() {}
+ RendererCanvasRender() {
+ ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCanvasRender singleton already exists.");
+ singleton = this;
+ }
+ virtual ~RendererCanvasRender() {
+ singleton = nullptr;
+ }
};
#endif // RENDERER_CANVAS_RENDER_H
diff --git a/servers/rendering/renderer_compositor.cpp b/servers/rendering/renderer_compositor.cpp
index d364de5633..428cecead1 100644
--- a/servers/rendering/renderer_compositor.cpp
+++ b/servers/rendering/renderer_compositor.cpp
@@ -47,6 +47,7 @@ bool RendererCompositor::is_xr_enabled() const {
}
RendererCompositor::RendererCompositor() {
+ ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCompositor singleton already exists.");
singleton = this;
#ifndef _3D_DISABLED
@@ -57,3 +58,7 @@ RendererCompositor::RendererCompositor() {
}
#endif // _3D_DISABLED
}
+
+RendererCompositor::~RendererCompositor() {
+ singleton = nullptr;
+}
diff --git a/servers/rendering/renderer_compositor.h b/servers/rendering/renderer_compositor.h
index 3c49e31516..ab789d5b4d 100644
--- a/servers/rendering/renderer_compositor.h
+++ b/servers/rendering/renderer_compositor.h
@@ -110,7 +110,7 @@ public:
static RendererCompositor *get_singleton() { return singleton; }
RendererCompositor();
- virtual ~RendererCompositor() {}
+ virtual ~RendererCompositor();
};
#endif // RENDERER_COMPOSITOR_H
diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp
index 14d138181f..84ea6a5da2 100644
--- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp
@@ -299,6 +299,7 @@ RendererCompositorRD::RendererCompositorRD() {
}
}
+ ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCompositorRD singleton already exists.");
singleton = this;
utilities = memnew(RendererRD::Utilities);
@@ -330,6 +331,7 @@ RendererCompositorRD::RendererCompositorRD() {
}
RendererCompositorRD::~RendererCompositorRD() {
+ singleton = nullptr;
memdelete(uniform_set_cache);
memdelete(framebuffer_cache);
ShaderRD::set_shader_cache_dir(String());