forked from Mirrorlandia_minetest/minetest
remove_detached_inventory: Fix segfault during mod load
This commit is contained in:
parent
fb6f1fdcbe
commit
b8131c3415
@ -2571,6 +2571,9 @@ void Server::sendDetachedInventory(const std::string &name, session_t peer_id)
|
|||||||
player_it->second.empty()) {
|
player_it->second.empty()) {
|
||||||
// OK. Send to everyone
|
// OK. Send to everyone
|
||||||
} else {
|
} else {
|
||||||
|
if (!m_env)
|
||||||
|
return; // Mods are not done loading
|
||||||
|
|
||||||
RemotePlayer *p = m_env->getPlayer(player_it->second.c_str());
|
RemotePlayer *p = m_env->getPlayer(player_it->second.c_str());
|
||||||
if (!p)
|
if (!p)
|
||||||
return; // Player is offline
|
return; // Player is offline
|
||||||
@ -3366,7 +3369,9 @@ Inventory* Server::createDetachedInventory(const std::string &name, const std::s
|
|||||||
Inventory *inv = new Inventory(m_itemdef);
|
Inventory *inv = new Inventory(m_itemdef);
|
||||||
sanity_check(inv);
|
sanity_check(inv);
|
||||||
m_detached_inventories[name] = inv;
|
m_detached_inventories[name] = inv;
|
||||||
|
if (!player.empty())
|
||||||
m_detached_inventories_player[name] = player;
|
m_detached_inventories_player[name] = player;
|
||||||
|
|
||||||
//TODO find a better way to do this
|
//TODO find a better way to do this
|
||||||
sendDetachedInventory(name,PEER_ID_INEXISTENT);
|
sendDetachedInventory(name,PEER_ID_INEXISTENT);
|
||||||
return inv;
|
return inv;
|
||||||
@ -3381,6 +3386,9 @@ bool Server::removeDetachedInventory(const std::string &name)
|
|||||||
delete inv_it->second;
|
delete inv_it->second;
|
||||||
m_detached_inventories.erase(inv_it);
|
m_detached_inventories.erase(inv_it);
|
||||||
|
|
||||||
|
if (!m_env) // Mods are not done loading
|
||||||
|
return true;
|
||||||
|
|
||||||
const auto &player_it = m_detached_inventories_player.find(name);
|
const auto &player_it = m_detached_inventories_player.find(name);
|
||||||
if (player_it != m_detached_inventories_player.end()) {
|
if (player_it != m_detached_inventories_player.end()) {
|
||||||
RemotePlayer *player = m_env->getPlayer(player_it->second.c_str());
|
RemotePlayer *player = m_env->getPlayer(player_it->second.c_str());
|
||||||
|
Loading…
Reference in New Issue
Block a user