summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-08-27 16:29:04 -0400
committerGitHub <noreply@github.com>2019-08-27 16:29:04 -0400
commit6c6be3c26335644bb65913a4db03388ec6ff4aab (patch)
tree9fb934a203a77431da2d0aea49086d247c9085fe /source
parente44a653e6a27c198010425792fdf9c97da163d0d (diff)
Two fixes to avoid random crash on destruction of GLRenderer (#1038)
* Two fixes to avoid random crash on destruction of GLRenderer * Use of a weak reference from objects created by GLRenderer, such that GLRenderer dtor can disable those objects assuming GLRenderer is live * Make sure window is not destroyed before the renderer * Used WeakSink for weak pointer.
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-smart-pointer.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/source/core/slang-smart-pointer.h b/source/core/slang-smart-pointer.h
index ebc6f20b0..1bbcffe47 100644
--- a/source/core/slang-smart-pointer.h
+++ b/source/core/slang-smart-pointer.h
@@ -249,8 +249,27 @@ namespace Slang
private:
T* pointer;
-
};
+
+ // Helper type for implementing weak pointers. The object being pointed at weakly creates a WeakSink object
+ // that other objects can reference and share. When the object is destroyed it detaches the sink
+ // doing so will make other users call to 'get' return null. Thus any user of the WeakSink, must check if the weakly pointed to
+ // things pointer is nullptr before using.
+ template <typename T>
+ class WeakSink : public RefObject
+ {
+ public:
+ WeakSink(T* ptr):
+ m_ptr(ptr)
+ {
+ }
+
+ SLANG_FORCE_INLINE T* get() const { return m_ptr; }
+ SLANG_FORCE_INLINE void detach() { m_ptr = nullptr; }
+
+ private:
+ T* m_ptr;
+ };
}
#endif