1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

fix segfault edge case in CObjectListWindow

This commit is contained in:
Laserlicht
2025-11-14 20:21:04 +01:00
committed by GitHub
parent 81db5c7cf4
commit 0aabc0947d

View File

@@ -1535,9 +1535,12 @@ CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::st
index(_id)
{
OBJECT_CONSTRUCTION;
auto imgIndex = parent->itemsVisible[index].first;
if(parent->images.size() > index && parent->images[imgIndex])
icon = std::make_shared<CPicture>(parent->images[imgIndex], Point(1, 1));
auto it = std::find(parent->items.begin(), parent->items.end(), parent->itemsVisible[index]);
int imgIndex = (it != parent->items.end()) ? std::distance(parent->items.begin(), it) : -1;
if(imgIndex >= 0 && imgIndex < parent->images.size() && parent->images[imgIndex])
icon = std::make_shared<CPicture>(parent->images[imgIndex], Point(1,1));
border = std::make_shared<CPicture>(ImagePath::builtin("TPGATES"));
pos = border->pos;