Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing cleanup and null checks for various singletons #93292

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions servers/rendering/renderer_canvas_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,13 @@ class RendererCanvasRender {

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
5 changes: 5 additions & 0 deletions servers/rendering/renderer_compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,3 +58,7 @@ RendererCompositor::RendererCompositor() {
}
#endif // _3D_DISABLED
}

RendererCompositor::~RendererCompositor() {
singleton = nullptr;
}
2 changes: 1 addition & 1 deletion servers/rendering/renderer_compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class RendererCompositor {

static RendererCompositor *get_singleton() { return singleton; }
RendererCompositor();
virtual ~RendererCompositor() {}
virtual ~RendererCompositor();
};

#endif // RENDERER_COMPOSITOR_H
2 changes: 2 additions & 0 deletions servers/rendering/renderer_rd/renderer_compositor_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ RendererCompositorRD::RendererCompositorRD() {
}
}

ERR_FAIL_COND_MSG(singleton != nullptr, "A RendererCompositorRD singleton already exists.");
singleton = this;

utilities = memnew(RendererRD::Utilities);
Expand Down Expand Up @@ -330,6 +331,7 @@ RendererCompositorRD::RendererCompositorRD() {
}

RendererCompositorRD::~RendererCompositorRD() {
singleton = nullptr;
memdelete(uniform_set_cache);
memdelete(framebuffer_cache);
ShaderRD::set_shader_cache_dir(String());
Expand Down
Loading