# HG changeset patch # User Santeri Piippo # Date 1372334132 -10800 # Node ID c731a22899a3be4a85a4a4960c44430a350eecfa # Parent fef00a6cbff0e7227de394c3062ba1736b88fbdc Use unique IDs instead of file indices in picking lists, this is much less prone to error diff -r fef00a6cbff0 -r c731a22899a3 src/gldraw.cpp --- a/src/gldraw.cpp Thu Jun 27 14:12:12 2013 +0300 +++ b/src/gldraw.cpp Thu Jun 27 14:55:32 2013 +0300 @@ -220,13 +220,11 @@ return; if (list == GL::PickList) { - // Make the color by the object's index color if we're picking, so we can - // make the index from the color we get from the picking results. Be sure - // to use the top level parent's index since inlinees don't have an index. - long i = obj->topLevelParent ()->getIndex (file ()); - - // We should have the index now. - assert (i != -1); + // Make the color by the object's ID if we're picking, so we can make the + // ID again from the color we get from the picking results. Be sure to use + // the top level parent's index since we want a subfile's children point + // to the subfile itself. + long i = obj->topLevelParent()->id(); // Calculate a color based from this index. This method caters for // 16777216 objects. I don't think that'll be exceeded anytime soon. :) @@ -1123,8 +1121,8 @@ // Go through each pixel read and add them to the selection. for (long i = 0; i < numpixels; ++i) { - uint32 idx = - (*(pixelptr) * 0x10000) + + long idx = + (*(pixelptr + 0) * 0x10000) + (*(pixelptr + 1) * 0x00100) + (*(pixelptr + 2) * 0x00001); pixelptr += 4; @@ -1132,7 +1130,7 @@ if (idx == 0xFFFFFF) continue; // White is background; skip - LDObject* obj = file ()->obj (idx); + LDObject* obj = LDObject::fromID( idx ); // If this is an additive single pick and the object is currently selected, // we remove it from selection instead. diff -r fef00a6cbff0 -r c731a22899a3 src/gui.cpp --- a/src/gui.cpp Thu Jun 27 14:12:12 2013 +0300 +++ b/src/gui.cpp Thu Jun 27 14:55:32 2013 +0300 @@ -587,7 +587,7 @@ delete obj; } - fullRefresh (); + refresh (); } // ============================================================================= diff -r fef00a6cbff0 -r c731a22899a3 src/ldtypes.cpp --- a/src/ldtypes.cpp Thu Jun 27 14:12:12 2013 +0300 +++ b/src/ldtypes.cpp Thu Jun 27 14:55:32 2013 +0300 @@ -76,6 +76,8 @@ id = obj->id() + 1; setID( id ); + + g_LDObjects << this; } LDGibberish::LDGibberish () {} @@ -215,12 +217,17 @@ LDObject::~LDObject () { // Remove this object from the selection array if it is there. - for (ulong i = 0; i < g_win->sel ().size(); ++i) + for (ulong i = 0; i < g_win->sel().size(); ++i) if (g_win->sel ()[i] == this) g_win->sel ().erase (i); // Delete the GL lists - GL::deleteLists (this); + GL::deleteLists( this ); + + // Remove this object from the list of LDObjects + ulong pos = g_LDObjects.find( this ); + if( pos < g_LDObjects.size()) + g_LDObjects.erase( pos ); } // ============================================================================= @@ -818,6 +825,15 @@ return repl; } +LDObject* LDObject::fromID (int id) { + for( LDObject* obj : g_LDObjects ) + if( obj->id() == id ) + return obj; + + return null; +} + + // ============================================================================= template void changeProperty (LDObject* obj, T* ptr, const T& val) { long idx; diff -r fef00a6cbff0 -r c731a22899a3 src/ldtypes.h --- a/src/ldtypes.h Thu Jun 27 14:12:12 2013 +0300 +++ b/src/ldtypes.h Thu Jun 27 14:55:32 2013 +0300 @@ -158,6 +158,7 @@ static void moveObjects (vector objs, const bool bUp); static str objectListContents (const vector& objs); + static LDObject* fromID( int id ); // Object list entry for this object QListWidgetItem* qObjListEntry;