Skip to content

Commit

Permalink
Fix Viewport Texture must be set to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilderin committed Sep 17, 2024
1 parent 6681f25 commit c11107b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
25 changes: 13 additions & 12 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
if (get_local_scene() && !path.is_empty()) {
setup_local_to_scene();
} else {
if (path.is_empty()) {
vp_changed = false;
}
emit_changed();
}
}
Expand All @@ -121,29 +124,23 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const {

int ViewportTexture::get_width() const {
if (!vp) {
if (!vp_pending) {
ERR_PRINT("Viewport Texture must be set to use it.");
}
_err_print_viewport_not_set();
return 0;
}
return vp->size.width;
}

int ViewportTexture::get_height() const {
if (!vp) {
if (!vp_pending) {
ERR_PRINT("Viewport Texture must be set to use it.");
}
_err_print_viewport_not_set();
return 0;
}
return vp->size.height;
}

Size2 ViewportTexture::get_size() const {
if (!vp) {
if (!vp_pending) {
ERR_PRINT("Viewport Texture must be set to use it.");
}
_err_print_viewport_not_set();
return Size2();
}
return vp->size;
Expand All @@ -163,14 +160,18 @@ bool ViewportTexture::has_alpha() const {

Ref<Image> ViewportTexture::get_image() const {
if (!vp) {
if (!vp_pending) {
ERR_PRINT("Viewport Texture must be set to use it.");
}
_err_print_viewport_not_set();
return Ref<Image>();
}
return RS::get_singleton()->texture_2d_get(vp->texture_rid);
}

void ViewportTexture::_err_print_viewport_not_set() const {
if (!vp_pending && !vp_changed) {
ERR_PRINT("Viewport Texture must be set to use it.");
}
}

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;
Expand Down
1 change: 1 addition & 0 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ViewportTexture : public Texture2D {
bool vp_changed = false;

void _setup_local_to_scene(const Node *p_loc_scene);
void _err_print_viewport_not_set() const;

mutable RID proxy_ph;
mutable RID proxy;
Expand Down

0 comments on commit c11107b

Please sign in to comment.