Clear inventory before setting lists
authorShadowNinja <shadowninja@minetest.net>
Fri, 13 Jun 2014 21:07:42 +0000 (17:07 -0400)
committerShadowNinja <shadowninja@minetest.net>
Mon, 23 Jun 2014 19:28:48 +0000 (15:28 -0400)
src/script/lua_api/l_inventory.cpp

index a45ae516851a298c2906e87aaf3e1eb712daf24c..f48f6083b21578407aff270cf6ce2b873153fc95 100644 (file)
@@ -271,19 +271,20 @@ int InvRef::l_set_lists(lua_State *L)
        if (!inv) {
                return 0;
        }
+
+       // Make a temporary inventory in case reading fails
+       Inventory *tempInv(inv);
+       tempInv->clear();
+
+       Server *server = getServer(L);
+
        lua_pushnil(L);
        while (lua_next(L, 2)) {
-               const char* listname = lua_tostring(L, -2);
-               InventoryList *list = inv->getList(listname);
-               if (list) {
-                       read_inventory_list(L, -1, inv, listname,
-                                       getServer(L), list->getSize());
-               } else {
-                       read_inventory_list(L, -1, inv, listname,
-                                       getServer(L));
-               }
+               const char *listname = lua_tostring(L, -2);
+               read_inventory_list(L, -1, tempInv, listname, server);
                lua_pop(L, 1);
        }
+       inv = tempInv;
        return 0;
 }