TF2-DMB / CBaseNPC

Provides a friendly interface for plugins to use in order to create custom NPCs on the game Team Fortress 2
37 stars 6 forks source link

Fix crash when uninstalling a CEntityFactory #24

Closed KitRifty closed 2 years ago

KitRifty commented 2 years ago

22 introduced std::map members into the CPluginEntityFactories singleton, however this introduced a case where uninstalling an entity factory would usually result in a crash. This is because in CPluginEntityFactories::RemovePluginFactory, the loop iterating through the map, if it found the factory, would erase it from the map. However, using erase on an iterator will invalidate the iterator. After erasing the element, the loop would continue and then increment from the invalidated iterator. Subsequent iterations of the loop would cause undefined behavior and eventually a crash.

This fixes the crash by adjusting the loop to advance to the iterator returned by erase, otherwise incrementing the iterator normally.