diff options
author | SmallJoker <mk939@ymail.com> | 2021-12-29 19:20:38 +0100 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2021-12-29 19:20:49 +0100 |
commit | 481bb90eac45651ba6f71860ed669341fcbef6f1 (patch) | |
tree | 5d9ee38b226a1f52f4b8191b2f84d5a73cc91100 /src/client | |
parent | 0fa54531d48eb2fcd09377a6fb8e7c81e09ada63 (diff) | |
download | minetest-481bb90eac45651ba6f71860ed669341fcbef6f1.tar.gz minetest-481bb90eac45651ba6f71860ed669341fcbef6f1.tar.bz2 minetest-481bb90eac45651ba6f71860ed669341fcbef6f1.zip |
Fix segfault in drawItems() due to missing inventory list
This fixes a nullptr dereference when the specified inventory list is not known.
Happens when HUD elements are sent before the required inventory list is created.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/hud.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/client/hud.cpp b/src/client/hud.cpp index e08d2ef02..6011a8cff 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -224,6 +224,7 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect, } //NOTE: selectitem = 0 -> no selected; selectitem 1-based +// mainlist can be NULL, but draw the frame anyway. void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction) { @@ -271,7 +272,8 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, // Draw items core::rect<s32> imgrect(0, 0, m_hotbar_imagesize, m_hotbar_imagesize); - for (s32 i = inv_offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) { + const s32 list_size = mainlist ? mainlist->getSize() : 0; + for (s32 i = inv_offset; i < itemcount && i < list_size; i++) { s32 fullimglen = m_hotbar_imagesize + m_padding * 2; v2s32 steppos; @@ -401,6 +403,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) break; } case HUD_ELEM_INVENTORY: { InventoryList *inv = inventory->getList(e->text); + if (!inv) + warningstream << "HUD: Unknown inventory list. name=" << e->text << std::endl; drawItems(pos, v2s32(e->offset.X, e->offset.Y), e->number, 0, inv, e->item, e->dir); break; } |