Ticket #2756: fix.patch

File fix.patch, 2.0 KB (added by Itms, 10 years ago)
  • source/simulation2/components/CCmpRangeManager.cpp

     
    15121512
    15131513    void UpdateVisibility(entity_id_t ent)
    15141514    {
     1515        // Warning: Code related to fogging (like posting VisibilityChanged messages) shouldn't be invoked while
     1516        // keeping an iterator to an element of m_EntityData because, by deleting mirage entities and so on,
     1517        // that code will change the indexes in the map, leading to segfaults.
    15151518        EntityMap<EntityData>::iterator itEnts = m_EntityData.find(ent);
    15161519        if (itEnts == m_EntityData.end())
    15171520            return;
    15181521
     1522        // So we just remember what visibilities to update and do that later.
    15191523        std::vector<u8> oldVisibilities;
    15201524        std::vector<u8> newVisibilities;
    15211525       
     
    16451649     */
    16461650    void SeeExploredEntities(player_id_t p)
    16471651    {
     1652        // Warning: Code related to fogging (like ForceMiraging) shouldn't be invoked while iterating
     1653        // through m_EntityData because, by deleting mirage entities and so on, that code will change the
     1654        // indexes in the map, leading to segfaults. So we just remember what entities to mirage and do that later.
     1655        std::vector<entity_id_t> miragableEntities;
     1656       
    16481657        for (EntityMap<EntityData>::iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it)
    16491658        {
    16501659            CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), it->first);
     
    16611670
    16621671            CmpPtr<ICmpFogging> cmpFogging(GetSimContext(), it->first);
    16631672            if (cmpFogging)
    1664                 cmpFogging->ForceMiraging(p);
     1673                miragableEntities.push_back(it->first);
    16651674        }
     1675
     1676        for (std::vector<entity_id_t>::iterator it = miragableEntities.begin(); it != miragableEntities.end(); ++it)
     1677        {
     1678            CmpPtr<ICmpFogging> cmpFogging(GetSimContext(), *it);
     1679            ENSURE(cmpFogging && "Impossible to retrieve Fogging component, previously achieved");
     1680            cmpFogging->ForceMiraging(p);
     1681        }
    16661682    }
    16671683
    16681684    /**