]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix builtin inventory list crash when size = 0 (#7297)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Sat, 5 May 2018 20:37:07 +0000 (22:37 +0200)
committerGitHub <noreply@github.com>
Sat, 5 May 2018 20:37:07 +0000 (22:37 +0200)
src/remoteplayer.cpp
src/script/cpp_api/s_item.cpp
src/server.cpp

index d070eb7e4cb40a01665d7d237219f9865aa0931a..e7c2462b625dc734cfb933c064c508f6eef5d8b1 100644 (file)
@@ -141,7 +141,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
 
        inventory.deSerialize(is);
 
-       if (inventory.getList("craftpreview") == NULL) {
+       if (!inventory.getList("craftpreview") && inventory.getList("craftresult")) {
                // Convert players without craftpreview
                inventory.addList("craftpreview", 1);
 
index 5d9d260831575ec5ff1746784a7465c135ac2acb..94abe267bdab7e0c2b04d74ef0619438df75af82 100644 (file)
@@ -177,7 +177,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
                const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
 {
        SCRIPTAPI_PRECHECKHEADER
-
+       sanity_check(old_craft_grid);
        int error_handler = PUSH_ERROR_HANDLER(L);
 
        lua_getglobal(L, "core");
index 9d4c133255bf4ad61c1eb40d8c4aa7291751f1ce..f151d09f024b863d63318481a831334cfc8f9539 100644 (file)
@@ -2685,6 +2685,10 @@ void Server::DeleteClient(session_t peer_id, ClientDeletionReason reason)
 
 void Server::UpdateCrafting(RemotePlayer *player)
 {
+       InventoryList *clist = player->inventory.getList("craft");
+       if (!clist || clist->getSize() == 0)
+               return;
+
        // Get a preview for crafting
        ItemStack preview;
        InventoryLocation loc;
@@ -2692,13 +2696,13 @@ void Server::UpdateCrafting(RemotePlayer *player)
        std::vector<ItemStack> output_replacements;
        getCraftingResult(&player->inventory, preview, output_replacements, false, this);
        m_env->getScriptIface()->item_CraftPredict(preview, player->getPlayerSAO(),
-                       (&player->inventory)->getList("craft"), loc);
+                       clist, loc);
 
-       // Put the new preview in
        InventoryList *plist = player->inventory.getList("craftpreview");
-       sanity_check(plist);
-       sanity_check(plist->getSize() >= 1);
-       plist->changeItem(0, preview);
+       if (plist && plist->getSize() >= 1) {
+               // Put the new preview in
+               plist->changeItem(0, preview);
+       }
 }
 
 void Server::handleChatInterfaceEvent(ChatEvent *evt)