Esempio n. 1
0
        /// <summary>
        /// When finished with the object, you should call Dispose() from the same thread that created the object.
        /// You can call this multiple times, but once is enough. If it isn't called before the object
        /// becomes inaccessible, then the destructor will call it and, if BlDebug.EnableDisposeErrors is
        /// true (it is true by default for Debug builds), then it will get an exception saying that it
        /// wasn't called by the same thread that created it. This is because the platform's underlying
        /// 3D library (OpenGL, etc.) often requires 3D resources to be managed only by one thread.
        /// </summary>
        public new void Dispose()
        {
            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("BlGame dispose");
            }
            if (IsDisposed)
            {
                return;
            }

            // We do NOT check for CreationThread, because it doesn't matter for this class
            //if (CreationThread != Thread.CurrentThread.ManagedThreadId && BlDebug.EnableThreadExceptions)
            //BlDebug.Message(String.Format("BlGame.Dispose() was called by thread {0} instead of thread {1}", Thread.CurrentThread.ManagedThreadId, CreationThread));

            GC.SuppressFinalize(this);

            base.Dispose();

            QueueMutex.Dispose();
            Graphics.Dispose();
#if WINDOWS
            WindowForm.Dispose();
#endif
            IsDisposed = true;

            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("end BlGame dispose");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// When finished with the object, you should call Dispose() from the same thread that created the object.
        /// You can call this multiple times, but once is enough. If it isn't called before the object
        /// becomes inaccessible, then the destructor will call it and, if BlDebug.EnableDisposeErrors is
        /// true (it is true by default for Debug builds), then it will get an exception saying that it
        /// wasn't called by the same thread that created it. This is because the platform's underlying
        /// 3D library (OpenGL, etc.) often requires 3D resources to be managed only by one thread.
        /// </summary>
        public new void Dispose()
        {
            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("BlGame dispose");
            }

            if (IsDisposed)
            {
                return;
            }

            if (CreationThread != Thread.CurrentThread.ManagedThreadId)
            {
                throw new Exception(String.Format("BlWindow.Dispose() was called by thread {0} instead of thread {1}", Thread.CurrentThread.ManagedThreadId, CreationThread));
            }

            GC.SuppressFinalize(this);

            base.Dispose();

            Graphics.Dispose();
            IsDisposed = true;

            if (BlDebug.ShowThreadInfo)
            {
                Console.WriteLine("end BlGame dispose");
            }
        }