Nimbin[12]?SDL & Graphics / mapcreator / commits / 74d51b8

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz

Fix use after free object

Christian Immanuel · 2026-02-19 14:42 · 74d51b8fe5ca514d262c30f554a282a6b69807be

 src/objects/object.cpp | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/objects/object.cpp b/src/objects/object.cpp
index 2e15682..adce898 100644
--- a/src/objects/object.cpp
+++ b/src/objects/object.cpp
@@ -17,21 +17,15 @@ Object::~Object() {
             size_t m_id = static_cast<size_t>((y+world_tile_position.y)*Map::size.x+(x+world_tile_position.x));
             if (m_id >= static_cast<size_t>(Map::size.x*Map::size.y))
                 continue;
-            std::vector<TileObject>& objects = Map::tile_map[m_id].objects;
+            std::vector<TileObject>& t_objects = Map::tile_map[m_id].objects;
 
-            for (auto it = objects.begin(); it != objects.end(); ) {
+            for (auto it = t_objects.begin(); it != t_objects.end(); ) {
                 if (it->object_id == id)
-                    it = objects.erase(it);
+                    it = t_objects.erase(it);
                 else ++it;
             }
         }
     }
-    for (auto it = objects.begin(); it != objects.end(); ++it) {
-        if (*it == this) {
-            objects.erase(it);
-            break;
-        }
-    }
 };
 
 const char* Object::to_String(ObjectType type) {
@@ -75,6 +69,7 @@ Object::get_ObjectByWorldPositionAndTilesetObjectID(SDL_Point position, size_t t
 
 Object*
 Object::get_ObjectById(size_t id) {
+    //std::cout << "GETTT " << id << std::endl;
     for (Object* object : Object::objects)
         if (object->id == id) return object;
     return nullptr;
@@ -314,7 +309,6 @@ Object::Remove(Object* obj) {
         for (int x = start_x; x < end_x; ++x) {
             size_t index = static_cast<size_t>(y * Map::size.x + x);
             if (index >= Map::tile_map.size()) continue;
-            std::cout << "xm " << x << "  " << y << std::endl;
 
             auto& tile_objects = Map::tile_map[index].objects;
 
@@ -326,5 +320,13 @@ Object::Remove(Object* obj) {
         }
     }
 
+    Object::objects.erase(
+            std::remove(Object::objects.begin(),
+                Object::objects.end(),
+                obj),
+            Object::objects.end()
+            );
+
+
     delete obj;
 }