Browse Source

Fix cycle detection

It used to detect duplicates, not just cycles.

--HG--
branch : minor
Bart van Strien 8 years ago
parent
commit
907630b04c
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/common/Variant.cpp

+ 5 - 2
src/common/Variant.cpp

@@ -198,9 +198,9 @@ Variant Variant::fromLua(lua_State *L, int n, std::set<const void*> *tableSet)
 				tableSetPtr.reset(tableSet = new std::set<const void*>);
 
 			// Now make sure this table wasn't already serialised
+			const void *tablePointer = lua_topointer(L, n);
 			{
-				const void *table = lua_topointer(L, n);
-				auto result = tableSet->insert(table);
+				auto result = tableSet->insert(tablePointer);
 				if (!result.second) // insertion failed
 					throw love::Exception("Cycle detected in table");
 			}
@@ -224,6 +224,9 @@ Variant Variant::fromLua(lua_State *L, int n, std::set<const void*> *tableSet)
 				}
 			}
 
+			// And remove the table from the set again
+			tableSet->erase(tablePointer);
+
 			if (success)
 				return Variant(table);
 			else