Пример #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
                if (disposing)
                {
                    // Dispose loaded game components
                    for (int i = 0; i < _components.Count; i++)
                    {
                        var disposable = _components[i] as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                    _components = null;

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

                    if (_graphicsDeviceManager != null)
                    {
                        (_graphicsDeviceManager as GraphicsDeviceManager).Dispose();
                        _graphicsDeviceManager = null;
                    }

                    if (Platform != null)
                    {
                        Platform.Activated   -= OnActivated;
                        Platform.Deactivated -= OnDeactivated;
                        _services.RemoveService(typeof(GamePlatform));
#if WINDOWS_STOREAPP
                        Platform.ViewStateChanged -= Platform_ApplicationViewChanged;
#endif
                        Platform.Dispose();
                        Platform = null;
                    }

                    Effect.FlushCache();
                    ContentTypeReaderManager.ClearTypeCreators();

#if WINDOWS_PHONE
                    TouchPanel.ResetState();
#endif

#if WINDOWS_MEDIA_SESSION
                    Media.MediaManagerState.CheckShutdown();
#endif

#if DIRECTX
                    SoundEffect.Shutdown();

                    BlendState.ResetStates();
                    DepthStencilState.ResetStates();
                    RasterizerState.ResetStates();
                    SamplerState.ResetStates();
#endif
                }
#if ANDROID
                Activity = null;
#endif
                _isDisposed = true;
                _instance   = null;
            }
        }