From fb1bcac2716c44e6c4fed9a6b029881fe19d1d2e Mon Sep 17 00:00:00 2001 From: Rindbee Date: Tue, 27 Jun 2023 06:12:50 +0800 Subject: [PATCH] Fix that `ViewportTexture` cannot be setup again after failed setup `vp_pending` is a flag indicating to wait for `ViewportTexture::_setup_local_to_scene` to be called. Once this method is called, no matter whether the setup will fail or not, it needs to be reset to `false`. --- scene/main/viewport.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index e15a8e48702..faa609d8477 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -170,6 +170,9 @@ Ref ViewportTexture::get_image() const { } void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) { + // Always reset this, even if this call fails with an error. + vp_pending = false; + Node *vpn = p_loc_scene->get_node_or_null(path); ERR_FAIL_NULL_MSG(vpn, "Path to node is invalid: '" + path + "'."); vp = Object::cast_to(vpn); @@ -186,7 +189,6 @@ void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) { ERR_FAIL_COND(proxy.is_valid()); // Should be invalid. proxy = RS::get_singleton()->texture_proxy_create(vp->texture_rid); } - vp_pending = false; vp_changed = false; emit_changed();