I spent waaaay too much time on this problem, I overlooked my code at least a hundred times, and this chunk of code should work perfectly fine...
The *only* client entity logic related code(also cant fit in this post):
http://coliru.stacked-crooked.com/a/496b028d24fd63f7
The client class:
http://coliru.stacked-crooked.com/a/a422909ed3d50b9a
(I used coliru because I find pastebin very distasteful)
The problem is that I get a seg fault in a loop that doesn't invalidate the iterator( or reference ) at all.
1 2 3 4 5 6
|
//Send update to clients that are in the clients view( because we see in a circle )
for(auto& InView_ID: Moved_Client.in_view_entities)
if(entities[InView_ID]->type == entity_client) //seg faults here from calling "InView_ID"
for(auto& an_client: clients)
if(InView_ID == an_client.second.id)
an_client.second.unrel_msgblk.emplace_back(a_msg);
|
It only happens when a client walks to the topleft corner of the map, a new client walks up to it, and when the client on the corner moves, it seg faults, or if the client that just walked up to it walks away from view, it also seg faults.
In the client logic code:
-line 33: crashes on the topleft client moving on
-line 249:crashes when the other client that walked into the topleft clients view walks away
-line 102: some dead code that technically isn't necessary, but would cause a crash.
Notes:
-"clients" is a map, but the seg fault existed before I made it like that.
-all the c++11 stuff used to be the older style(like push_back & iterator loops), but the error existed before I changed it to that( hoping that it would fix it :c ).
-You have to walk your client to the top left before the other client sees you for the seg fault.
I could take some extensive debugging techniques that are made to solve problems like this( I'm using mingw with codeblocks ).