public void CleanUp(System.ComponentModel.CancelEventArgs e = null, bool crash = false) { if (!crash) { for (int i = 0; i < graphs.Count; ++i) { UIGraph g = graphs[i]; LayoutDocument doc = documents[i]; if (g.Modified && !g.ReadOnly) { var result = MessageBox.Show(this, g.GraphName + " " + Properties.Resources.TITLE_HAS_BEEN_MODIFIED, Properties.Resources.TITLE_SAVE_CHANGES, MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { HandleSave(g, doc); } else if (result == MessageBoxResult.Cancel) { if (e != null) { e.Cancel = true; return; } } } } } recent.Save(); //release all opengl content foreach (UIGraph g in graphs) { if (crash) { if (!string.IsNullOrEmpty(g.FilePath)) { if (g.FromArchive) { if (string.IsNullOrEmpty(g.FromArchivePath)) { g.Save(g.FilePath + ".recovery.mtga", true); } else { g.Save(g.FromArchivePath + ".recovery.mtga", true); } } else { g.Save(g.FilePath + ".recovery.mtg", true); } } } g.DeleteTempArchiveData(); g.Release(); } graphs.Clear(); FontManager.Release(); FunctionGraph.ReleaseShaderBuffer(); //clear material and shader caches PBRMaterial.ReleaseBRDF(); ImageProcessor.ReleaseAll(); Material.Material.ReleaseAll(); //release gl view if (UI3DPreview.Instance != null) { UI3DPreview.Instance.Release(); } if (UIPreviewPane.Instance != null) { UIPreviewPane.Instance.Release(); } ViewContext.Dispose(); }