Пример #1
0
        /// <summary>
        /// Destroy the shared memory space and temporary scene objects
        /// </summary>
        public void Teardown()
        {
            if (!IsRunning)
            {
                return;
            }

            IsRunning = false;

            AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
            EditorApplication.update        -= OnEditorUpdate;
            SceneManager.activeSceneChanged -= OnSceneUnloaded;
            EditorSceneManager.activeSceneChangedInEditMode -= OnSceneUnloaded;

            // Notify Blender if we're shutting down from the Unity side
            if (IsConnected)
            {
                messages.WriteDisconnect();
                OnDisconnectFromBlender();
            }
            else
            {
                // Still clear if we're not connected - we might've torn down
                // the connection uncleanly and have some persisted data to clean up.
                Clear();
            }

            // Dispose shared memory
            messages?.Dispose();
            messages = null;

            pixelsProducer?.Dispose();
            pixelsProducer = null;
        }
Пример #2
0
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            try
            {
                // Remove the event handler
                if (Application.Current != null)
                {
                    Utils.UIInvoke(DispatcherPriority.Normal, () =>
                    {
                        Application.Current.Exit -= OnApplicationExit;
                    });
                }
            }
            catch { }

            if (AudioDevice != null)
            {
                AudioDevice.Stop();
                AudioDevice.Dispose();
                AudioDevice = null;
            }

            if (AudioBuffer != null)
            {
                AudioBuffer.Dispose();
                AudioBuffer = null;
            }
        }
Пример #3
0
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            try
            {
                // Remove the event handler
                if (Application.Current != null)
                {
                    MediaElement.InvokeOnUI(() =>
                    {
                        Application.Current.Exit -= OnApplicationExit;
                    });
                }
            }
            catch { }

            if (AudioDevice != null)
            {
                AudioDevice.Stop();
                AudioDevice.Dispose();
                AudioDevice = null;
            }

            if (AudioBuffer != null)
            {
                AudioBuffer.Dispose();
                AudioBuffer = null;
            }
        }
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            lock (SyncLock)
            {
                if (AudioDevice != null)
                {
                    AudioDevice.Dispose();
                    AudioDevice = null;
                }

                if (AudioBuffer != null)
                {
                    AudioBuffer.Dispose();
                    AudioBuffer = null;
                }

                if (AudioProcessor == null)
                {
                    return;
                }

                AudioProcessor.Dispose();
                AudioProcessor = null;
            }
        }
Пример #5
0
        /// <summary>
        /// Destroy the shared memory space and temporary scene objects
        /// </summary>
        public void Teardown()
        {
            AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
            EditorApplication.update -= OnEditorUpdate;

            // Notify Blender if we're shutting down from the Unity side
            if (IsConnected)
            {
                messages.WriteDisconnect();
                OnDisconnectFromBlender();
            }
            else
            {
                // Still clear if we're not connected - we might've torn down
                // the connection uncleanly and have some persisted data to clean up.
                Clear();
            }

            IsSetup = false;

            Debug.Log("Tearing down shared memory space");

            // Dispose shared memory
            messages?.Dispose();
            messages = null;

            pixelsProducer?.Dispose();
            pixelsProducer = null;
        }
Пример #6
0
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            try
            {
                if (Application.Current != null)
                {
                    Runner.UIInvoke(DispatcherPriority.Send, () =>
                    {
                        Application.Current.Exit -= OnApplicationExit;
                    });
                }
            }
            catch { }

            if (AudioDevice != null)
            {
                AudioDevice.Pause();
                AudioDevice.Dispose();
                AudioDevice = null;
            }

            if (AudioBuffer != null)
            {
                AudioBuffer.Dispose();
                AudioBuffer = null;
            }

            if (AudioProcessor != null)
            {
                AudioProcessor.Dispose();
                AudioProcessor = null;
            }
        }
Пример #7
0
        public void Dispose()
        {
            this._sendQueue?.CompleteAdding();
            _stopping = true;

            try { _sender?.Dispose(); } catch { /* ignored*/ }
            try { _reciever?.Dispose(); } catch { /* ignored*/ }
            _sender   = null;
            _reciever = null;
        }
Пример #8
0
        public void Dispose()
        {
            outboundQueue?.Clear();

            messageProducer?.Dispose();
            messageProducer = null;

            messageConsumer?.Dispose();
            messageConsumer = null;
        }
Пример #9
0
        public void Return_Arrays_To_Pool_On_Dispose()
        {
            var pool = new RememberingPool(ArrayPool <byte> .Shared);
            var sut  = new CircularBuffer(pool);

            sut.WriteStream.Write(new byte[] { 7, 5, 6, 8 }, 0, 4);

            sut.Dispose();

            pool.HasCurrentRentArrays.Should().BeFalse();
        }
Пример #10
0
 private void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         OnDispose(disposing);
         if (disposing)
         {
             CircularBuffer.Dispose();
         }
         _disposed = true;
     }
 }
Пример #11
0
        /// <summary>
        /// Dispose shared memory and shutdown communication to Unity.
        ///
        /// Anything from Unity's side would get cleaned up.
        /// </summary>
        public void Disconnect()
        {
            messages?.WriteDisconnect();

            IsConnectedToUnity        = false;
            IsConnectedToSharedMemory = false;

            messages?.Dispose();
            messages = null;

            pixelsConsumer?.Dispose();
            pixelsConsumer = null;
        }
Пример #12
0
        public void SimpleReadWrite()
        {
            var circularBuffer = new CircularBuffer();
            var referenceData  = new byte[] { 1 };

            circularBuffer.Write(referenceData, 0, referenceData.Length);
            var readData = new byte[10];

            Assert.AreEqual(1, circularBuffer.Read(readData, 0, readData.Length));
            Assert.AreEqual(referenceData[0], readData[0]);
            circularBuffer.Dispose();
            Assert.AreEqual(0, circularBuffer.Read(readData, 0, readData.Length));
        }
Пример #13
0
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            if (AudioDevice != null)
            {
                AudioDevice.Stop();
                AudioDevice.Dispose();
                AudioDevice = null;
            }

            if (AudioBuffer != null)
            {
                AudioBuffer.Dispose();
                AudioBuffer = null;
            }
        }
Пример #14
0
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            lock (SyncLock)
            {
                try
                {
                    if (Application.Current != null)
                    {
                        WindowsPlatform.Instance.Gui?.Invoke(DispatcherPriority.Send, () =>
                        {
                            Application.Current.Exit -= OnApplicationExit;
                        });
                    }
                }
                catch
                {
                    // ignored
                }

                if (AudioDevice != null)
                {
                    AudioDevice.Pause();
                    AudioDevice.Dispose();
                    AudioDevice = null;
                }

                if (AudioBuffer != null)
                {
                    AudioBuffer.Dispose();
                    AudioBuffer = null;
                }

                if (AudioProcessor != null)
                {
                    AudioProcessor.Dispose();
                    AudioProcessor = null;
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            try
            {
                if (Application.Current != null)
                {
                    Application.Current.Exit -= OnApplicationExit;
                }
            }
            catch { }

            if (AudioDevice != null)
            {
                AudioDevice.Stop();
                AudioDevice.Dispose();
                AudioDevice = null;
            }

            if (AudioBuffer != null)
            {
                AudioBuffer.Dispose();
                AudioBuffer = null;
            }
        }
Пример #16
0
 public override void Dispose()
 {
     frameInfoBuffer.Dispose();
 }
Пример #17
0
 /// <summary/>
 public void Dispose()
 {
     _assembler?.Dispose();
     _privateBuffer?.Dispose();
     _circularBuffer?.Dispose();
 }
Пример #18
0
        /* Overrides */

        /// <summary/>
        public void Dispose()
        {
            _circularBuffer?.Dispose();
            _shellCode?.Dispose();
        }
Пример #19
0
 /// <inheritdoc/>
 public void Dispose()
 {
     _circularBuffer?.Dispose();
     ShellCode?.Dispose();
     GC.SuppressFinalize(this);
 }
Пример #20
0
 public void Dispose()
 {
     _circularBuffer?.Dispose();
 }
Пример #21
0
 /// <inheritdoc />
 protected override void OnDispose(bool disposing)
 {
     _circularBuffer.Dispose();
 }
Пример #22
0
        public void UnsafePeekTest_With_Overflow()
        {
            Random rnd = new Random(1337);

            byte[] buffer = new byte[9];
            rnd.NextBytes(buffer);

            CircularBuffer cb = new CircularBuffer(16);

            byte[] dummy = new byte[100];

            fixed(byte *src = dummy)
            {
                Assert.AreEqual(0, cb.Peek(src, 78, 0));
            }

            cb.Write(buffer, 0, buffer.Length);
            fixed(byte *src = dummy)
            {
                Assert.AreEqual(buffer.Length, cb.Peek(src, 78, 0));
            }

            cb.Dispose();

            cb = new CircularBuffer(16);
            cb.Write(buffer, 0, buffer.Length);

            cb.Write(buffer, 0, buffer.Length);

            Assert.AreEqual(cb.Count, 16);

            byte[] readBuffer2 = new byte[9];
            fixed(byte *src = readBuffer2)
            {
                Assert.AreEqual(7, cb.Peek(src, readBuffer2.Length, 9));
            }

            Assert.AreEqual(cb.Count, 16);
            Assert.IsFalse(cb.IsEmpty);

            Assert.IsTrue(readBuffer2.Take(7).SequenceEqual(buffer.Take(7)));

            cb.Dispose();

            cb = new CircularBuffer(16);
            cb.Write(buffer, 0, buffer.Length);

            byte[] readBuffer4 = new byte[9];
            fixed(byte *src = readBuffer4)
            {
                Assert.AreEqual(9, cb.Read(src, readBuffer4.Length, 0));
            }

            Assert.AreEqual(0, cb.Count);
            Assert.IsTrue(cb.IsEmpty);

            cb.Write(buffer, 0, buffer.Length);
            fixed(byte *src = readBuffer4)
            {
                Assert.AreEqual(9, cb.Peek(src, readBuffer4.Length, 0));
            }

            Assert.AreEqual(cb.Count, 9);
            Assert.IsFalse(cb.IsEmpty);

            cb.Dispose();

            cb = new CircularBuffer(16);
            cb.Write(buffer, 0, buffer.Length);
            fixed(byte *src = readBuffer4)
            {
                Assert.AreEqual(9, cb.Read(src, readBuffer4.Length, 0));
            }

            Assert.AreEqual(0, cb.Count);
            Assert.IsTrue(cb.IsEmpty);

            cb.Write(buffer, 0, buffer.Length);
            fixed(byte *src = readBuffer4)
            {
                Assert.AreEqual(1, cb.Peek(src, 1, 8));
            }

            Assert.AreEqual(9, cb.Count);
            Assert.IsFalse(cb.IsEmpty);

            Assert.IsTrue(readBuffer4.Take(1).SequenceEqual(buffer.Skip(8).Take(1)));
        }
Пример #23
0
        public void SafeReadTest_With_Overflow()
        {
            Random rnd = new Random(1337);

            byte[] buffer = new byte[9];
            rnd.NextBytes(buffer);

            CircularBuffer cb = new CircularBuffer(16);

            byte[] dummy = new byte[100];
            Assert.AreEqual(0, cb.Read(dummy, 0, 78, 0));

            cb.Write(buffer, 0, buffer.Length);

            Assert.AreEqual(buffer.Length, cb.Read(dummy, 0, 78, 0));

            cb.Dispose();

            cb = new CircularBuffer(16);
            cb.Write(buffer, 0, buffer.Length);

            cb.Write(buffer, 0, buffer.Length);

            Assert.AreEqual(cb.Count, 16);

            byte[] readBuffer2 = new byte[9];
            Assert.AreEqual(readBuffer2.Length, cb.Read(readBuffer2, 0, readBuffer2.Length, 0));

            Assert.AreEqual(cb.Count, 16 - 9);
            Assert.IsFalse(cb.IsEmpty);

            Assert.IsTrue(readBuffer2.Take(9).SequenceEqual(buffer));

            cb.Dispose();

            cb = new CircularBuffer(16);
            cb.Write(buffer, 0, buffer.Length);

            byte[] readBuffer4 = new byte[9];
            Assert.AreEqual(9, cb.Read(readBuffer4, 0, readBuffer4.Length, 0));

            Assert.AreEqual(cb.Count, 0);
            Assert.IsTrue(cb.IsEmpty);

            cb.Write(buffer, 0, buffer.Length);

            Assert.AreEqual(9, cb.Read(readBuffer4, 0, readBuffer4.Length, 0));
            Assert.AreEqual(cb.Count, 0);
            Assert.IsTrue(cb.IsEmpty);

            cb.Dispose();

            cb = new CircularBuffer(16);
            cb.Write(buffer, 0, buffer.Length);

            Assert.AreEqual(9, cb.Read(readBuffer4, 0, readBuffer4.Length, 0));

            Assert.AreEqual(cb.Count, 0);
            Assert.IsTrue(cb.IsEmpty);

            cb.Write(buffer, 0, buffer.Length);

            Assert.AreEqual(1, cb.Read(readBuffer4, 0, 1, 8));
            Assert.AreEqual(cb.Count, 0);
            Assert.IsTrue(cb.IsEmpty);

            Assert.IsTrue(readBuffer4.Take(1).SequenceEqual(buffer.Skip(8).Take(1)));
        }
Пример #24
0
 public void Dispose()
 {
     _circularBuffer?.Dispose();
     _circularBuffer = null;
 }