diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2021-08-13 12:32:01 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2021-08-13 12:32:01 +0300 |
commit | 8f70232a15c09703190e4b2d43ef6726c0f60aa4 (patch) | |
tree | 2de5390602736444d41325e83d0901fb8cdd04fe /scene/resources | |
parent | 39efccf3b8298e30aa67a726ffd8752b3dff4c66 (diff) |
Add placeholder textures to ensure CameraTexture / CameraFeed always have valid RIDs.
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/texture.cpp | 9 | ||||
-rw-r--r-- | scene/resources/texture.h | 1 |
2 files changed, 8 insertions, 2 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 2ea55843ad..4ad5f2a506 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -2587,7 +2587,10 @@ RID CameraTexture::get_rid() const { if (feed.is_valid()) { return feed->get_texture(which_feed); } else { - return RID(); + if (_texture.is_null()) { + _texture = RenderingServer::get_singleton()->texture_2d_placeholder_create(); + } + return _texture; } } @@ -2643,5 +2646,7 @@ bool CameraTexture::get_camera_active() const { CameraTexture::CameraTexture() {} CameraTexture::~CameraTexture() { - // nothing to do here yet + if (_texture.is_valid()) { + RenderingServer::get_singleton()->free(_texture); + } } diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 98aa61138d..2e97c2deb1 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -812,6 +812,7 @@ class CameraTexture : public Texture2D { GDCLASS(CameraTexture, Texture2D); private: + mutable RID _texture; int camera_feed_id = 0; CameraServer::FeedImage which_feed = CameraServer::FEED_RGBA_IMAGE; |