fix fatal error on invalid item id in inventory

This commit is contained in:
MihailRis 2025-12-16 00:17:51 +03:00
parent 77b4382577
commit 180dd5051b
4 changed files with 27 additions and 2 deletions

View file

@ -4,6 +4,7 @@
#include <glm/gtx/norm.hpp>
#include "Player.hpp"
#include "content/Content.hpp"
#include "items/Inventories.hpp"
#include "world/Level.hpp"
#include "world/World.hpp"
@ -87,7 +88,9 @@ Player* Players::create(int64_t id) {
auto player = playerPtr.get();
add(std::move(playerPtr));
level.inventories->store(player->getInventory());
auto inventory = player->getInventory();
inventory->check(*level.content.getIndices());
level.inventories->store(std::move(inventory));
return player;
}
@ -147,6 +150,7 @@ void Players::deserialize(const dv::value& src) {
if (inventory->getId() == 0) {
inventory->setId(level.getWorld()->getNextInventoryId());
}
level.inventories->store(player->getInventory());
inventory->check(*level.content.getIndices());
level.inventories->store(inventory);
}
}