internal void Dispose() { GLAudioEngine.SoundStopAll(); lock (_gameObjects) { _gameObjects.Clear(); _gameObjectsTBA.Clear(); _gameObjectsTBR.Clear(); } lock (_particleObjects) { _particleObjects.Clear(); _particleObjectsTBA.Clear(); _particleObjectsTBR.Clear(); } lock (_hudObjects) { _hudObjects.Clear(); _hudObjectsTBA.Clear(); _hudObjectsTBR.Clear(); } lock (_lightObjects) { CurrentWindow.InitializeFramebuffersLightsList(); for (int i = 0; i < _lightObjects.Count; i++) { if (_lightObjects[i].IsShadowCaster) { _lightObjects[i] = null; } } _lightObjects.Clear(); for (int i = 0; i < _lightObjectsTBA.Count; i++) { if (_lightObjectsTBA[i].IsShadowCaster) { _lightObjectsTBA[i] = null; } } _lightObjectsTBA.Clear(); for (int i = 0; i < _lightObjectsTBR.Count; i++) { if (_lightObjectsTBR[i].IsShadowCaster) { _lightObjectsTBR[i] = null; } } _lightObjectsTBR.Clear(); } lock (_explosionObjects) { _explosionObjects.Clear(); _explosionObjectsTBA.Clear(); _explosionObjectsTBR.Clear(); } lock (KWEngine.Models) { List <string> removableModels = new List <string>(); foreach (string m in KWEngine.Models.Keys) { if (KWEngine.Models[m].AssemblyMode != SceneImporter.AssemblyMode.Internal) { KWEngine.Models[m].Dispose(); removableModels.Add(m); } } foreach (string m in removableModels) { KWEngine.Models.Remove(m); } } if (KWEngine.CustomTextures.ContainsKey(this)) { Dictionary <string, int> dict = KWEngine.CustomTextures[this]; foreach (int texId in dict.Values) { GL.DeleteTexture(texId); } dict.Clear(); KWEngine.CustomTextures.Remove(this); } GL.Flush(); GL.Finish(); GC.Collect(GC.MaxGeneration); }