So much for that pointer class, caused more problems than it solved. For instance splitting a second quad after a first one had been split would trigger a peculiar crash...

Sat, 16 Mar 2013 17:50:13 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 16 Mar 2013 17:50:13 +0200
changeset 22
335e430a6b4f
parent 21
9aebaaafa5da
child 23
69a91c1ff583

So much for that pointer class, caused more problems than it solved. For instance splitting a second quad after a first one had been split would trigger a peculiar crash...

common.h file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
io.cpp file | annotate | diff | comparison | revisions
io.h file | annotate | diff | comparison | revisions
ldforge.pro file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
model.cpp file | annotate | diff | comparison | revisions
pointer.cpp file | annotate | diff | comparison | revisions
pointer.h file | annotate | diff | comparison | revisions
zz_setContentsDialog.cpp file | annotate | diff | comparison | revisions
--- a/common.h	Sat Mar 16 16:59:16 2013 +0200
+++ b/common.h	Sat Mar 16 17:50:13 2013 +0200
@@ -131,6 +131,4 @@
 typedef uint32_t xulong;
 typedef uint64_t xulonglong;
 
-#include "pointer.h"
-
 #endif
\ No newline at end of file
--- a/gui.cpp	Sat Mar 16 16:59:16 2013 +0200
+++ b/gui.cpp	Sat Mar 16 17:50:13 2013 +0200
@@ -35,6 +35,8 @@
 	createMenus ();
 	createToolbars ();
 	
+	slot_selectionChanged ();
+	
 	setTitle ();
 	setMinimumSize (320, 200);
 	resize (800, 600);
@@ -229,7 +231,6 @@
 	line->dColor = 24;
 	
 	g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulSpot, line);
-	g_CurrentFile->objects[ulSpot].serialize ();
 	
 	buildObjList ();
 	R->hardRefresh ();
@@ -305,10 +306,14 @@
 			continue; // Was not selected
 		
 		static_cast<LDQuad*> (obj)->splitToTriangles ();
+		i++;// Skip past the second triangle
 	}
 	
+	printf ("build obj list\n");
+	buildObjList ();
+	
+	printf ("refresh teh renderer\n");
 	R->hardRefresh ();
-	buildObjList ();
 }
 
 void LDForgeWindow::slot_setContents () {
@@ -377,8 +382,9 @@
 	
 	qObjList->clear ();
 	
-	for (ushort i = 0; i < g_CurrentFile->objects.size(); ++i) {
+	for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) {
 		LDObject* obj = g_CurrentFile->objects[i];
+		printf ("%lu: %p\n", i, obj);
 		
 		str zText;
 		switch (obj->getType ()) {
@@ -463,6 +469,9 @@
 void LDForgeWindow::slot_selectionChanged () {
 	// If the selection isn't 1 exact, disable setting contents
 	qAct_setContents->setEnabled (qObjList->selectedItems().size() == 1);
+	
+	// If we have no selection, disable splitting quads
+	qAct_splitQuads->setEnabled (qObjList->selectedItems().size() > 0);
 }
 
 // =============================================================================
--- a/io.cpp	Sat Mar 16 16:59:16 2013 +0200
+++ b/io.cpp	Sat Mar 16 17:50:13 2013 +0200
@@ -72,10 +72,6 @@
 		}
 	}
 	
-	// Serialize all of the objects
-	for (ulong i = 0; i < load->objects.size(); ++i)
-		load->objects[i].serialize ();
-	
 	g_LoadedFiles.push_back (load);
 	g_CurrentFile = g_LoadedFiles[g_LoadedFiles.size() - 1];
 	
--- a/io.h	Sat Mar 16 16:59:16 2013 +0200
+++ b/io.h	Sat Mar 16 17:50:13 2013 +0200
@@ -8,7 +8,7 @@
 class OpenFile {
 public:
 	str zFileName, zTitle;
-	vector<objPointer> objects;
+	vector<LDObject*> objects;
 };
 
 // PROTOTYPES
--- a/ldforge.pro	Sat Mar 16 16:59:16 2013 +0200
+++ b/ldforge.pro	Sat Mar 16 17:50:13 2013 +0200
@@ -20,7 +20,6 @@
 	str.h \
 	config.h \
 	cfgdef.h \
-	pointer.h \
 	zz_setContentsDialog.h
 
 SOURCES += bbox.cpp \
@@ -34,7 +33,6 @@
 	scanner.cpp \
 	str.cpp \ 
 	config.cpp \
-	pointer.cpp \
 	zz_setContentsDialog.cpp
 
 QMAKE_CXXFLAGS += -std=c++0x
--- a/ldtypes.cpp	Sat Mar 16 16:59:16 2013 +0200
+++ b/ldtypes.cpp	Sat Mar 16 17:50:13 2013 +0200
@@ -2,7 +2,6 @@
 #include "ldtypes.h"
 #include "io.h"
 #include "misc.h"
-#include "pointer.h"
 
 const char* g_saObjTypeNames[] = {
 	"unidentified",
@@ -164,7 +163,7 @@
 	// Find the index of this quad
 	ulong ulIndex;
 	for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex)
-		if (g_CurrentFile->objects[ulIndex].ptr == this)
+		if (g_CurrentFile->objects[ulIndex] == this)
 			break;
 	
 	if (ulIndex >= g_CurrentFile->objects.size()) {
@@ -190,18 +189,16 @@
 	tri2->vaCoords[1] = vaCoords[2];
 	tri2->vaCoords[2] = vaCoords[3];
 	
+	printf ("triangles: %p %p\n", tri1, tri2);
+	
 	// The triangles also inherit the quad's color
 	tri1->dColor = tri2->dColor = dColor;
 	
-	// Replace the quad with the first triangle
-	objPointer::replacePointers (this, tri1);
+	// Replace the quad with the first triangle and add the second triangle
+	// after the first one.
+	g_CurrentFile->objects[ulIndex] = tri1;
+	g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulIndex + 1, tri2);
 	
-	// Add the second triangle after the first one.
-	objPointer ptr (tri2);
-	ptr.serialize ();
-	g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulIndex, ptr);
-	
-	// Delete this quad now, it has been split. `delete this` isn't exactly
-	// safe in my experience so we'll tell objPointer to delete the quad.
-	objPointer::deleteObj (this);
+	// Delete this quad now, it has been split.
+	delete this;
 }
\ No newline at end of file
--- a/model.cpp	Sat Mar 16 16:59:16 2013 +0200
+++ b/model.cpp	Sat Mar 16 17:50:13 2013 +0200
@@ -11,10 +11,8 @@
 	for (ushort i = 0; i < g_LoadedFiles.size(); i++) {
 		OpenFile* f = g_LoadedFiles[i];
 		
-		for (ushort j = 0; j < f->objects.size(); ++j) {
-			f->objects[i].unSerialize ();
+		for (ushort j = 0; j < f->objects.size(); ++j)
 			delete (LDObject*)f->objects[j];
-		}
 		
 		delete f;
 	}
--- a/pointer.cpp	Sat Mar 16 16:59:16 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-#include "pointer.h"
-
-vector<objPointer*> g_pObjectPointers;
-
-void objPointer::replacePointers (LDObject* old, LDObject* repl) {
-	for (ulong i = 0; i < g_pObjectPointers.size(); ++i) {
-		objPointer* ptrptr = g_pObjectPointers[i];
-		
-		if ((*ptrptr).ptr == old)
-			(*ptrptr).ptr = repl;
-	}
-}
-
-objPointer::~objPointer () {
-	
-}
-
-objPointer::objPointer () {
-	ptr = nullptr;
-}
-
-objPointer::objPointer (LDObject* _ptr) {
-	ptr = _ptr;
-}
-
-void objPointer::serialize () {
-	g_pObjectPointers.push_back (this);
-}
-
-void objPointer::unSerialize () {
-	for (ulong i = 0; i < g_pObjectPointers.size(); ++i)
-		if (g_pObjectPointers[i] == this)
-			g_pObjectPointers.erase (g_pObjectPointers.begin() + i);
-}
-
-void objPointer::deleteObj (LDObject* obj) {
-	replacePointers (obj, nullptr);
-	delete obj;
-}
\ No newline at end of file
--- a/pointer.h	Sat Mar 16 16:59:16 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-#ifndef __POINTER_H__
-#define __POINTER_H__
-
-#include "ldtypes.h"
-#include <vector>
-using std::vector;
-
-class objPointer;
-extern vector<objPointer*> g_pObjectPointers;
-
-#define POINTER_LDCAST(T) \
-	operator T* () { \
-		return static_cast<T*> (ptr); \
-	}
-
-class objPointer {
-public:
-	LDObject* ptr;
-	
-	objPointer ();
-	objPointer (LDObject*);
-	~objPointer ();
-	
-	void serialize ();
-	void unSerialize ();
-	static void replacePointers (LDObject* old, LDObject* repl);
-	static void deleteObj (LDObject*);
-	
-	LDObject& operator* () {
-		return *ptr;
-	}
-	
-	LDObject* operator-> () {
-		return ptr;
-	}
-	
-	operator LDObject* () {
-		return ptr;
-	}
-	
-	POINTER_LDCAST (LDComment)
-	POINTER_LDCAST (LDCondLine)
-	POINTER_LDCAST (LDQuad)
-	POINTER_LDCAST (LDTriangle)
-	POINTER_LDCAST (LDSubfile)
-	POINTER_LDCAST (LDGibberish)
-	POINTER_LDCAST (LDVector)
-	POINTER_LDCAST (LDVertex)
-	POINTER_LDCAST (LDLine)
-	
-	LDObject* operator= (LDObject* repl) {
-		ptr = repl;
-		return ptr;
-	}
-};
-
-#endif // __POINTER_H__
-class LDLine;
--- a/zz_setContentsDialog.cpp	Sat Mar 16 16:59:16 2013 +0200
+++ b/zz_setContentsDialog.cpp	Sat Mar 16 17:50:13 2013 +0200
@@ -70,7 +70,10 @@
 		delete oldobj;
 		
 		// Replace all instances of the old object with the new object
-		objPointer::replacePointers (oldobj, obj);
+		for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) {
+			if (g_CurrentFile->objects[i] == oldobj)
+				g_CurrentFile->objects[i] = obj;
+		}
 		
 		// Rebuild stuff after this
 		parent->buildObjList ();

mercurial