Fix builtin inventory list crash when size = 0 (#7297)
parent
21c720755b
commit
d99a033fd6
|
@ -141,7 +141,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
|
||||||
|
|
||||||
inventory.deSerialize(is);
|
inventory.deSerialize(is);
|
||||||
|
|
||||||
if (inventory.getList("craftpreview") == NULL) {
|
if (!inventory.getList("craftpreview") && inventory.getList("craftresult")) {
|
||||||
// Convert players without craftpreview
|
// Convert players without craftpreview
|
||||||
inventory.addList("craftpreview", 1);
|
inventory.addList("craftpreview", 1);
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
|
||||||
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
|
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
|
||||||
{
|
{
|
||||||
SCRIPTAPI_PRECHECKHEADER
|
SCRIPTAPI_PRECHECKHEADER
|
||||||
|
sanity_check(old_craft_grid);
|
||||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||||
|
|
||||||
lua_getglobal(L, "core");
|
lua_getglobal(L, "core");
|
||||||
|
|
|
@ -2685,6 +2685,10 @@ void Server::DeleteClient(session_t peer_id, ClientDeletionReason reason)
|
||||||
|
|
||||||
void Server::UpdateCrafting(RemotePlayer *player)
|
void Server::UpdateCrafting(RemotePlayer *player)
|
||||||
{
|
{
|
||||||
|
InventoryList *clist = player->inventory.getList("craft");
|
||||||
|
if (!clist || clist->getSize() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
// Get a preview for crafting
|
// Get a preview for crafting
|
||||||
ItemStack preview;
|
ItemStack preview;
|
||||||
InventoryLocation loc;
|
InventoryLocation loc;
|
||||||
|
@ -2692,14 +2696,14 @@ void Server::UpdateCrafting(RemotePlayer *player)
|
||||||
std::vector<ItemStack> output_replacements;
|
std::vector<ItemStack> output_replacements;
|
||||||
getCraftingResult(&player->inventory, preview, output_replacements, false, this);
|
getCraftingResult(&player->inventory, preview, output_replacements, false, this);
|
||||||
m_env->getScriptIface()->item_CraftPredict(preview, player->getPlayerSAO(),
|
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");
|
InventoryList *plist = player->inventory.getList("craftpreview");
|
||||||
sanity_check(plist);
|
if (plist && plist->getSize() >= 1) {
|
||||||
sanity_check(plist->getSize() >= 1);
|
// Put the new preview in
|
||||||
plist->changeItem(0, preview);
|
plist->changeItem(0, preview);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Server::handleChatInterfaceEvent(ChatEvent *evt)
|
void Server::handleChatInterfaceEvent(ChatEvent *evt)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue