Fixed crashing when closing all

Tue, 30 Jul 2013 02:27:12 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 30 Jul 2013 02:27:12 +0300
changeset 400
af39fae829f6
parent 399
13d24c6eb423
child 401
89a9235b47d3

Fixed crashing when closing all

src/file.cpp file | annotate | diff | comparison | revisions
--- a/src/file.cpp	Thu Jul 18 13:13:26 2013 +0300
+++ b/src/file.cpp	Tue Jul 30 02:27:12 2013 +0300
@@ -102,8 +102,6 @@
 
 // =============================================================================
 LDOpenFile::~LDOpenFile() {
-	ulong currentIndex = 0;
-	
 	// Clear everything from the model
 	for (LDObject* obj : m_objs)
 		delete obj;
@@ -115,7 +113,6 @@
 	// Remove this file from the list of files
 	for (ulong i = 0; i < g_loadedFiles.size(); ++i) {
 		if (g_loadedFiles[i] == this) {
-			currentIndex = i;
 			g_loadedFiles.erase (i);
 			break;
 		}
@@ -123,19 +120,12 @@
 	
 	// If we just closed the current file, we need to set the current
 	// file as something else.
-	if (this == LDOpenFile::current()) {
-		ulong i = currentIndex;
-		if (i > 0)
-			i--;
-		
-		while (i != -1u && g_loadedFiles[i]->implicit())
-			--i;
-		
+	if( this == LDOpenFile::current() ) {
 		// If we closed the last file, create a blank one.
-		if (i == -1u)
+		if( g_loadedFiles.size() == 0 )
 			newFile();
 		else
-			LDOpenFile::setCurrent (g_loadedFiles[i]);
+			LDOpenFile::setCurrent( g_loadedFiles[0] );
 	}
 	
 	g_win->updateFileList();
@@ -447,11 +437,9 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void closeAll() {
-	if (!g_loadedFiles.size())
-		return;
-	
 	// Remove all loaded files and the objects they contain
-	for (LDOpenFile* file : g_loadedFiles)
+	vector<LDOpenFile*> files = g_loadedFiles;
+	for( LDOpenFile* file : files )
 		delete file;
 }
 

mercurial