Skip to content

Commit 2a8d30a

Browse files
committed
Merge pull request #97029 from Hilderin/fix-viewport-texture-must-be-set-to-use-it
Fix Viewport Texture must be set to use it
2 parents b103381 + c11107b commit 2a8d30a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

scene/main/viewport.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
111111
if (get_local_scene() && !path.is_empty()) {
112112
setup_local_to_scene();
113113
} else {
114+
if (path.is_empty()) {
115+
vp_changed = false;
116+
}
114117
emit_changed();
115118
}
116119
}
@@ -121,29 +124,23 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const {
121124

122125
int ViewportTexture::get_width() const {
123126
if (!vp) {
124-
if (!vp_pending) {
125-
ERR_PRINT("Viewport Texture must be set to use it.");
126-
}
127+
_err_print_viewport_not_set();
127128
return 0;
128129
}
129130
return vp->size.width;
130131
}
131132

132133
int ViewportTexture::get_height() const {
133134
if (!vp) {
134-
if (!vp_pending) {
135-
ERR_PRINT("Viewport Texture must be set to use it.");
136-
}
135+
_err_print_viewport_not_set();
137136
return 0;
138137
}
139138
return vp->size.height;
140139
}
141140

142141
Size2 ViewportTexture::get_size() const {
143142
if (!vp) {
144-
if (!vp_pending) {
145-
ERR_PRINT("Viewport Texture must be set to use it.");
146-
}
143+
_err_print_viewport_not_set();
147144
return Size2();
148145
}
149146
return vp->size;
@@ -163,14 +160,18 @@ bool ViewportTexture::has_alpha() const {
163160

164161
Ref<Image> ViewportTexture::get_image() const {
165162
if (!vp) {
166-
if (!vp_pending) {
167-
ERR_PRINT("Viewport Texture must be set to use it.");
168-
}
163+
_err_print_viewport_not_set();
169164
return Ref<Image>();
170165
}
171166
return RS::get_singleton()->texture_2d_get(vp->texture_rid);
172167
}
173168

169+
void ViewportTexture::_err_print_viewport_not_set() const {
170+
if (!vp_pending && !vp_changed) {
171+
ERR_PRINT("Viewport Texture must be set to use it.");
172+
}
173+
}
174+
174175
void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) {
175176
// Always reset this, even if this call fails with an error.
176177
vp_pending = false;

scene/main/viewport.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ViewportTexture : public Texture2D {
6363
bool vp_changed = false;
6464

6565
void _setup_local_to_scene(const Node *p_loc_scene);
66+
void _err_print_viewport_not_set() const;
6667

6768
mutable RID proxy_ph;
6869
mutable RID proxy;

0 commit comments

Comments
 (0)