Пример #1
0
        /// <summary>
        /// Revives instance without acquiring it.
        /// </summary>
        private void Revive()
        {
            // Return if already revived.
            if (IsRevived)
            {
                return;
            }


            // Return if no bytes are available.
            if (Bytes == null)
            {
                return;
            }


            // Allocate and initialize memory (returning if allocation failed).
            var memory = CubismMemory.AllocateUnmanaged(Bytes.Length, csmAlignofMoc);


            if (memory == IntPtr.Zero)
            {
                return;
            }


            CubismMemory.Write(Bytes, memory);


            // Try revive.
            UnmanagedMoc = csmReviveMocInPlace(memory, (uint)Bytes.Length);
        }
        /// <summary>
        /// Actually releases native resource(s).
        /// </summary>
        private void OnReleaseUnmanaged()
        {
            CubismMemory.DeallocateUnmanaged(UnmanagedModel);
            Moc.ReleaseUnmanagedMoc();


            UnmanagedModel = IntPtr.Zero;
        }
        /// <summary>
        /// Initializes instance.
        /// </summary>
        /// <param name="moc">Moc unmanaged model was instantiated from.</param>
        public CubismTaskableModel(CubismMoc moc)
        {
            Moc = moc;


            // Allocate unmanaged memory and instantiate unmanaged model.
            var unmanagedMoc = moc.AcquireUnmanagedMoc();
            var size         = csmGetSizeofModel(unmanagedMoc);
            var memory       = CubismMemory.AllocateUnmanaged((int)size, csmAlignofModel);


            UnmanagedModel = csmInitializeModelInPlace(unmanagedMoc, memory, size);


            Lock  = new object();
            State = TaskState.Idle;
            DynamicDrawableData    = CubismDynamicDrawableData.CreateData(UnmanagedModel);
            ShouldReleaseUnmanaged = false;
        }
Пример #4
0
        /// <summary>
        /// Releases native handle.
        /// </summary>
        public void ReleaseUnmanagedMoc()
        {
            --ReferenceCount;


            // Free unmanaged memory in case the instance isn't referenced any longer.
            if (ReferenceCount == 0)
            {
                CubismMemory.DeallocateUnmanaged(UnmanagedMoc);


                UnmanagedMoc = IntPtr.Zero;
            }


            // Deal with invalid reference counts.
            else if (ReferenceCount < 0)
            {
                ReferenceCount = 0;
            }
        }