don't crash if g_CurrentFile is null

Fri, 15 Mar 2013 20:39:29 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 15 Mar 2013 20:39:29 +0200
changeset 3
2b78cf8634c3
parent 2
d71faa0a6133
child 4
758302636564

don't crash if g_CurrentFile is null

bbox.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
main.cpp file | annotate | diff | comparison | revisions
--- a/bbox.cpp	Fri Mar 15 20:35:47 2013 +0200
+++ b/bbox.cpp	Fri Mar 15 20:39:29 2013 +0200
@@ -3,6 +3,9 @@
 #include "ldtypes.h"
 
 void bbox::calculate () {
+	if (!g_CurrentFile)
+		return;
+	
 	// The bounding box, bbox for short, is the
 	// box that encompasses the model we have open.
 	// v0 is the minimum vertex, v1 is the maximum vertex.
--- a/gui.cpp	Fri Mar 15 20:35:47 2013 +0200
+++ b/gui.cpp	Fri Mar 15 20:39:29 2013 +0200
@@ -279,7 +279,13 @@
 }
 
 void LDForgeWindow::buildObjList () {
+	if (!g_CurrentFile)
+		return;
+	
 	QList<QTreeWidgetItem*> qaItems;
+	
+	qObjList->clear ();
+	
 	for (ushort i = 0; i < g_CurrentFile->objects.size(); ++i) {
 		LDObject* obj = g_CurrentFile->objects[i];
 		
--- a/main.cpp	Fri Mar 15 20:35:47 2013 +0200
+++ b/main.cpp	Fri Mar 15 20:39:29 2013 +0200
@@ -12,9 +12,11 @@
 	g_CurrentFile = IO_ParseLDFile ("55966.dat");
 	g_BBox.calculate();
 	
-	printf ("bbox: (%.3f, %.3f, %.3f), (%.3f, %.3f, %.3f)\n",
-		FVERTEX (g_BBox.v0), FVERTEX (g_BBox.v1));
-	printf ("%u objects\n", g_CurrentFile->objects.size());
+	if (g_CurrentFile) {
+		printf ("bbox: (%.3f, %.3f, %.3f), (%.3f, %.3f, %.3f)\n",
+			FVERTEX (g_BBox.v0), FVERTEX (g_BBox.v1));
+		printf ("%u objects\n", g_CurrentFile->objects.size());
+	}
 	
 	QApplication app (argc, argv);
 	LDForgeWindow* win = new LDForgeWindow;

mercurial