Browse Source

Merge pull request #81198 from KoBeWi/MissingRID

Add placeholder RID to GradientTexture1D
Rémi Verschelde 2 years ago
parent
commit
80bfca20c6
2 changed files with 11 additions and 4 deletions
  1. 9 2
      scene/resources/gradient_texture.cpp
  2. 2 2
      scene/resources/gradient_texture.h

+ 9 - 2
scene/resources/gradient_texture.cpp

@@ -64,11 +64,11 @@ void GradientTexture1D::set_gradient(Ref<Gradient> p_gradient) {
 		return;
 		return;
 	}
 	}
 	if (gradient.is_valid()) {
 	if (gradient.is_valid()) {
-		gradient->disconnect_changed(callable_mp(this, &GradientTexture1D::_update));
+		gradient->disconnect_changed(callable_mp(this, &GradientTexture1D::_queue_update));
 	}
 	}
 	gradient = p_gradient;
 	gradient = p_gradient;
 	if (gradient.is_valid()) {
 	if (gradient.is_valid()) {
-		gradient->connect_changed(callable_mp(this, &GradientTexture1D::_update));
+		gradient->connect_changed(callable_mp(this, &GradientTexture1D::_queue_update));
 	}
 	}
 	_queue_update();
 	_queue_update();
 	emit_changed();
 	emit_changed();
@@ -164,6 +164,13 @@ bool GradientTexture1D::is_using_hdr() const {
 	return use_hdr;
 	return use_hdr;
 }
 }
 
 
+RID GradientTexture1D::get_rid() const {
+	if (!texture.is_valid()) {
+		texture = RS::get_singleton()->texture_2d_placeholder_create();
+	}
+	return texture;
+}
+
 Ref<Image> GradientTexture1D::get_image() const {
 Ref<Image> GradientTexture1D::get_image() const {
 	const_cast<GradientTexture1D *>(this)->update_now();
 	const_cast<GradientTexture1D *>(this)->update_now();
 	if (!texture.is_valid()) {
 	if (!texture.is_valid()) {

+ 2 - 2
scene/resources/gradient_texture.h

@@ -39,7 +39,7 @@ class GradientTexture1D : public Texture2D {
 private:
 private:
 	Ref<Gradient> gradient;
 	Ref<Gradient> gradient;
 	bool update_pending = false;
 	bool update_pending = false;
-	RID texture;
+	mutable RID texture;
 	int width = 256;
 	int width = 256;
 	bool use_hdr = false;
 	bool use_hdr = false;
 
 
@@ -59,7 +59,7 @@ public:
 	void set_use_hdr(bool p_enabled);
 	void set_use_hdr(bool p_enabled);
 	bool is_using_hdr() const;
 	bool is_using_hdr() const;
 
 
-	virtual RID get_rid() const override { return texture; }
+	virtual RID get_rid() const override;
 	virtual int get_height() const override { return 1; }
 	virtual int get_height() const override { return 1; }
 	virtual bool has_alpha() const override { return true; }
 	virtual bool has_alpha() const override { return true; }