Navigation Menu

Skip to content

Commit

Permalink
Fix builtin inventory list crash when size = 0 (#7297)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed May 5, 2018
1 parent 21c7207 commit d99a033
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/remoteplayer.cpp
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/script/cpp_api/s_item.cpp
Expand Up @@ -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");
Expand Down
14 changes: 9 additions & 5 deletions src/server.cpp
Expand Up @@ -2685,20 +2685,24 @@ 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;
loc.setPlayer(player->getName());
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)
Expand Down

0 comments on commit d99a033

Please sign in to comment.