Don't change RID
when changing viewport_path
in ViewportTexture
When changing `viewport_path`, the `proxy`'s target is changed to a new placeholder. Add a flag `vp_changed` to prevent calling `setup_local_to_scene` (mainly called by toggling `resource_local_to_scene`) when the target viewport has not changed.
This commit is contained in:
parent
ca1b4eb225
commit
7532b2d259
@ -61,6 +61,11 @@
|
|||||||
#include "servers/rendering/rendering_server_globals.h"
|
#include "servers/rendering/rendering_server_globals.h"
|
||||||
|
|
||||||
void ViewportTexture::setup_local_to_scene() {
|
void ViewportTexture::setup_local_to_scene() {
|
||||||
|
// For the same target viewport, setup is only allowed once to prevent multiple free or multiple creations.
|
||||||
|
if (!vp_changed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (vp_pending) {
|
if (vp_pending) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,20 +94,17 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
path = p_path;
|
path = p_path;
|
||||||
|
vp_changed = true;
|
||||||
|
|
||||||
if (vp) {
|
if (vp) {
|
||||||
vp->viewport_textures.erase(this);
|
vp->viewport_textures.erase(this);
|
||||||
vp = nullptr;
|
vp = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy_ph.is_valid()) {
|
if (proxy.is_valid() && proxy_ph.is_null()) {
|
||||||
RS::get_singleton()->free(proxy_ph);
|
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
|
||||||
|
RS::get_singleton()->texture_proxy_update(proxy, proxy_ph);
|
||||||
}
|
}
|
||||||
if (proxy.is_valid()) {
|
|
||||||
RS::get_singleton()->free(proxy);
|
|
||||||
}
|
|
||||||
proxy_ph = RID();
|
|
||||||
proxy = RID();
|
|
||||||
|
|
||||||
if (get_local_scene() && !path.is_empty()) {
|
if (get_local_scene() && !path.is_empty()) {
|
||||||
setup_local_to_scene();
|
setup_local_to_scene();
|
||||||
@ -181,11 +183,13 @@ void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) {
|
|||||||
if (proxy_ph.is_valid()) {
|
if (proxy_ph.is_valid()) {
|
||||||
RS::get_singleton()->texture_proxy_update(proxy, vp->texture_rid);
|
RS::get_singleton()->texture_proxy_update(proxy, vp->texture_rid);
|
||||||
RS::get_singleton()->free(proxy_ph);
|
RS::get_singleton()->free(proxy_ph);
|
||||||
|
proxy_ph = RID();
|
||||||
} else {
|
} else {
|
||||||
ERR_FAIL_COND(proxy.is_valid()); // Should be invalid.
|
ERR_FAIL_COND(proxy.is_valid()); // Should be invalid.
|
||||||
proxy = RS::get_singleton()->texture_proxy_create(vp->texture_rid);
|
proxy = RS::get_singleton()->texture_proxy_create(vp->texture_rid);
|
||||||
}
|
}
|
||||||
vp_pending = false;
|
vp_pending = false;
|
||||||
|
vp_changed = false;
|
||||||
|
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ class ViewportTexture : public Texture2D {
|
|||||||
friend class Viewport;
|
friend class Viewport;
|
||||||
Viewport *vp = nullptr;
|
Viewport *vp = nullptr;
|
||||||
bool vp_pending = false;
|
bool vp_pending = false;
|
||||||
|
bool vp_changed = false;
|
||||||
|
|
||||||
void _setup_local_to_scene(const Node *p_loc_scene);
|
void _setup_local_to_scene(const Node *p_loc_scene);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user