== and != operators for Ref<T> / T*

This is to prevent crashes for code like:

...
void Material::set_next_pass(const Ref<Material> &p_pass) {

	ERR_FAIL_COND(p_pass == this);
...

that's been fixed in 031f763d4f
This commit is contained in:
Marcin Zawiejski 2018-08-21 00:47:26 +02:00
parent 238b70e2db
commit a1d2fbdeb2
2 changed files with 8 additions and 1 deletions

View file

@ -87,6 +87,13 @@ class Ref {
//virtual Reference * get_reference() const { return reference; }
public:
_FORCE_INLINE_ bool operator==(const T *p_ptr) const {
return reference == p_ptr;
}
_FORCE_INLINE_ bool operator!=(const T *p_ptr) const {
return reference != p_ptr;
}
_FORCE_INLINE_ bool operator<(const Ref<T> &p_r) const {
return reference < p_r.reference;

View file

@ -34,7 +34,7 @@
void Material::set_next_pass(const Ref<Material> &p_pass) {
ERR_FAIL_COND(p_pass.ptr() == this);
ERR_FAIL_COND(p_pass == this);
if (next_pass == p_pass)
return;