diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2018-05-05 22:37:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-05 22:37:07 +0200 |
commit | d99a033fd692546a29cfd4728dbbc5d26ac5c37f (patch) | |
tree | 6fc92d79c0d5e294534a839ad4f5fbcbd66e0685 /src | |
parent | 21c720755bfc9fa54fbb2722e0dd5cfbd96f8814 (diff) | |
download | minetest-d99a033fd692546a29cfd4728dbbc5d26ac5c37f.tar.gz minetest-d99a033fd692546a29cfd4728dbbc5d26ac5c37f.tar.bz2 minetest-d99a033fd692546a29cfd4728dbbc5d26ac5c37f.zip |
Fix builtin inventory list crash when size = 0 (#7297)
Diffstat (limited to 'src')
-rw-r--r-- | src/remoteplayer.cpp | 2 | ||||
-rw-r--r-- | src/script/cpp_api/s_item.cpp | 2 | ||||
-rw-r--r-- | src/server.cpp | 14 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp index d070eb7e4..e7c2462b6 100644 --- a/src/remoteplayer.cpp +++ b/src/remoteplayer.cpp @@ -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); diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index 5d9d26083..94abe267b 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -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"); diff --git a/src/server.cpp b/src/server.cpp index 9d4c13325..f151d09f0 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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) |