bonkmaykr
@bonkmaykr@canithesis.org
40 following 24 followers
I managed to figure it out, IDK the low-level specifics but basically since updating world objects happens in the middle of a for() that reads the vector, it would see the new object get added to the end of the vector and try to call it's updateMe() while the vector was getting shifted around. Adding a lag of one game tick before each new object spawns by giving them a queue to wait in helped work around the issue. So I just do this before each tick:
for (globals::objects::o_worldObjectGeneric* o : w_contentQueue) w_content.push_back(o); w_contentQueue.clear();
@bonkmaykr You should generally avoid adding to a vector while iterating over it, especially if you're using the for(auto x : y)
syntax. What can happen is that when you try to push onto the vector and there's no more space, the vector allocates a new buffer and moves all the objects into it. This doesn't change the for loop iterators, so your for loop continues to loop over the destructed and freed objects.