]> git.jsancho.org Git - lugaru.git/commitdiff
This should fix the segfault from #89
authorCôme Chilliet <come@chilliet.eu>
Mon, 30 Jan 2017 18:13:08 +0000 (19:13 +0100)
committerCôme Chilliet <come@chilliet.eu>
Mon, 30 Jan 2017 18:13:08 +0000 (19:13 +0100)
Source/Environment/Terrain.cpp
Source/Environment/Terrain.hpp
Source/Objects/Object.cpp

index 4874e337bcd1fa5e532597a414afa67a48fc5283..2530f0a873f5b156fc2c4b8c8a9c1b815a3c2ae1 100644 (file)
@@ -1241,6 +1241,26 @@ void Terrain::AddObject(XYZ where, float radius, int id)
     }
 }
 
+void Terrain::DeleteObject(unsigned int id)
+{
+    for (int i = 0; i < subdivision; i++) {
+        for (int j = 0; j < subdivision; j++) {
+            for (unsigned int k = 0; k < patchobjects[i][j].size();) {
+                if (patchobjects[i][j][k] == id) {
+                    /* Remove all occurences of id (there should never be more than 1 though) */
+                    patchobjects[i][j].erase(patchobjects[i][j].begin() + k);
+                } else {
+                    /* Update id of other objects if needed */
+                    if (patchobjects[i][j][k] > id) {
+                        patchobjects[i][j][k]--;
+                    }
+                    k++;
+                }
+            }
+        }
+    }
+}
+
 void Terrain::DeleteDecal(int which)
 {
     if (decalstoggle) {
index 6132c6a48ba07a91f2e1e779a9f16e478360480f..f4876cf19f9c75ecdc52e363116ab05fdd45c16b 100644 (file)
@@ -87,6 +87,7 @@ public:
     std::vector<Decal> decals;
 
     void AddObject(XYZ where, float radius, int id);
+    void DeleteObject(unsigned int id);
     void DeleteDecal(int which);
     void MakeDecal(decal_type type, XYZ where, float size, float opacity, float rotation);
     void MakeDecalLock(decal_type type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation);
index a7d991d6907e1a81360f910ae199cfbc838d35f5..84cc17353b84b487274acd4a478ac33f60029f70 100644 (file)
@@ -636,6 +636,7 @@ void Object::Draw()
 void Object::DeleteObject(int which)
 {
     objects.erase(objects.begin() + which);
+    terrain.DeleteObject(which);
 }
 
 void Object::MakeObject(int atype, XYZ where, float ayaw, float apitch, float ascale)