forked from Mirrorlandia_minetest/minetest
Fix some potential iterator invalidation issues
This commit is contained in:
parent
9ac6d330b4
commit
2b97fead9e
@ -70,14 +70,13 @@ public:
|
|||||||
}
|
}
|
||||||
void dereg(MtEvent::Type type, event_receive_func f, void *data) override
|
void dereg(MtEvent::Type type, event_receive_func f, void *data) override
|
||||||
{
|
{
|
||||||
std::map<MtEvent::Type, Dest>::iterator i = m_dest.find(type);
|
auto i = m_dest.find(type);
|
||||||
if (i != m_dest.end()) {
|
if (i != m_dest.end()) {
|
||||||
std::list<FuncSpec> &funcs = i->second.funcs;
|
std::list<FuncSpec> &funcs = i->second.funcs;
|
||||||
auto j = funcs.begin();
|
for (auto j = funcs.begin(); j != funcs.end(); ) {
|
||||||
while (j != funcs.end()) {
|
|
||||||
bool remove = (j->f == f && (!data || j->d == data));
|
bool remove = (j->f == f && (!data || j->d == data));
|
||||||
if (remove)
|
if (remove)
|
||||||
funcs.erase(j++);
|
j = funcs.erase(j);
|
||||||
else
|
else
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
|
@ -1336,15 +1336,14 @@ void Server::handleCommand_RemovedSounds(NetworkPacket* pkt)
|
|||||||
|
|
||||||
*pkt >> id;
|
*pkt >> id;
|
||||||
|
|
||||||
std::unordered_map<s32, ServerPlayingSound>::iterator i =
|
auto i = m_playing_sounds.find(id);
|
||||||
m_playing_sounds.find(id);
|
|
||||||
if (i == m_playing_sounds.end())
|
if (i == m_playing_sounds.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ServerPlayingSound &psound = i->second;
|
ServerPlayingSound &psound = i->second;
|
||||||
psound.clients.erase(pkt->getPeerId());
|
psound.clients.erase(pkt->getPeerId());
|
||||||
if (psound.clients.empty())
|
if (psound.clients.empty())
|
||||||
m_playing_sounds.erase(i++);
|
m_playing_sounds.erase(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2924,12 +2924,11 @@ void Server::DeleteClient(session_t peer_id, ClientDeletionReason reason)
|
|||||||
/*
|
/*
|
||||||
Clear references to playing sounds
|
Clear references to playing sounds
|
||||||
*/
|
*/
|
||||||
for (std::unordered_map<s32, ServerPlayingSound>::iterator
|
for (auto i = m_playing_sounds.begin(); i != m_playing_sounds.end();) {
|
||||||
i = m_playing_sounds.begin(); i != m_playing_sounds.end();) {
|
|
||||||
ServerPlayingSound &psound = i->second;
|
ServerPlayingSound &psound = i->second;
|
||||||
psound.clients.erase(peer_id);
|
psound.clients.erase(peer_id);
|
||||||
if (psound.clients.empty())
|
if (psound.clients.empty())
|
||||||
m_playing_sounds.erase(i++);
|
i = m_playing_sounds.erase(i);
|
||||||
else
|
else
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ class IWritableItemDefManager;
|
|||||||
class NodeDefManager;
|
class NodeDefManager;
|
||||||
class IWritableCraftDefManager;
|
class IWritableCraftDefManager;
|
||||||
class BanManager;
|
class BanManager;
|
||||||
class EventManager;
|
|
||||||
class Inventory;
|
class Inventory;
|
||||||
class ModChannelMgr;
|
class ModChannelMgr;
|
||||||
class RemotePlayer;
|
class RemotePlayer;
|
||||||
|
@ -123,9 +123,9 @@ void BanManager::add(const std::string &ip, const std::string &name)
|
|||||||
void BanManager::remove(const std::string &ip_or_name)
|
void BanManager::remove(const std::string &ip_or_name)
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(m_mutex);
|
MutexAutoLock lock(m_mutex);
|
||||||
for (StringMap::iterator it = m_ips.begin(); it != m_ips.end();) {
|
for (auto it = m_ips.begin(); it != m_ips.end();) {
|
||||||
if ((it->first == ip_or_name) || (it->second == ip_or_name)) {
|
if ((it->first == ip_or_name) || (it->second == ip_or_name)) {
|
||||||
m_ips.erase(it++);
|
it = m_ips.erase(it);
|
||||||
m_modified = true;
|
m_modified = true;
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
|
@ -1616,8 +1616,7 @@ void ServerEnvironment::step(float dtime)
|
|||||||
Manage particle spawner expiration
|
Manage particle spawner expiration
|
||||||
*/
|
*/
|
||||||
if (m_particle_management_interval.step(dtime, 1.0)) {
|
if (m_particle_management_interval.step(dtime, 1.0)) {
|
||||||
for (std::unordered_map<u32, float>::iterator i = m_particle_spawners.begin();
|
for (auto i = m_particle_spawners.begin(); i != m_particle_spawners.end(); ) {
|
||||||
i != m_particle_spawners.end(); ) {
|
|
||||||
// non expiring spawners
|
// non expiring spawners
|
||||||
if (i->second == PARTICLE_SPAWNER_NO_EXPIRY) {
|
if (i->second == PARTICLE_SPAWNER_NO_EXPIRY) {
|
||||||
++i;
|
++i;
|
||||||
@ -1626,7 +1625,7 @@ void ServerEnvironment::step(float dtime)
|
|||||||
|
|
||||||
i->second -= 1.0f;
|
i->second -= 1.0f;
|
||||||
if (i->second <= 0.f)
|
if (i->second <= 0.f)
|
||||||
m_particle_spawners.erase(i++);
|
i = m_particle_spawners.erase(i);
|
||||||
else
|
else
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user