diff --git a/GlitchyEngine/src/Helper.bf b/GlitchyEngine/src/Helper.bf new file mode 100644 index 0000000..6e70ced --- /dev/null +++ b/GlitchyEngine/src/Helper.bf @@ -0,0 +1,23 @@ +using System; +using DirectX.Common; + +namespace GlitchyEngine +{ + static + { + /// Releases the reference to destination, writes newValue into it and adds a reference to newValue. + public static mixin SetReference(T destination, T newValue) where T: RefCounted + { + destination?.ReleaseRef(); + destination = newValue; + destination?.AddRef(); + } + + /// Releases the reference to value and nullifies it. + public static mixin ReleaseRefAndNullify(T value) where T: RefCounted + { + value?.ReleaseRef(); + value = null; + } + } +}