From 7a9acd5aca6e37c4f36180136fa9e224f9950a43 Mon Sep 17 00:00:00 2001 From: aaronp64 Date: Wed, 24 Apr 2024 15:18:56 -0400 Subject: [PATCH] Fix SubViewport/AudioStreamPlayer2D crash Updated Viewport destructor to remove itself from World2D, to avoid World2D keeping invalid pointers. --- scene/main/viewport.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index a370ef2d189f..10ca19dbfdfe 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -5048,6 +5048,9 @@ Viewport::~Viewport() { for (ViewportTexture *E : viewport_textures) { E->vp = nullptr; } + if (world_2d.is_valid()) { + world_2d->remove_viewport(this); + } ERR_FAIL_NULL(RenderingServer::get_singleton()); RenderingServer::get_singleton()->free(viewport); }