The simulation is perfectly working on 800x800m maps, but I don't know why, when I go over this size, I've a random crash happening at a random place (with cout, I just saw that sometimes it crashes after a point, but sometimes it crashes before...).
The only thing I'm sure about is that it never pass again in my slotted function (called withn a timer and which is working with smaller map).
1 2 3 4 5 6 7 8
void Widget::stepEcosys() {
if (_ecosys != nullptr) {
_ecosys->step(true); // sometimes crash happen inside this function
// sometimes happen between these both functions
this->update();
// sometimes get here but never loop again
}
}
Thank you for help.
Edit: My code is pretty long so I don't know what to post, so don't hesitate to ask to me.
Is it possible that _ecosys can be pointing to just random memory, or to an object that has already been deleted? Do you have a guarantee that it will always either be nullptr, or that the object it points to will never have been destroyed?
_ecosys->step(true); // sometimes crash happen inside this function
Well what code is inside that function? On what line inside that function is the crash?
There's only one instance of Ecosys and no delete of it (I'm sure of that).
When I say the program is crashing inside the step() function, well there's no precise location, that's totally random. Here's the code if it may help you:
Well, line 24 looks dubious. Next: On line 36 you send the local variable pointerMap as a reference to a thread but it will be invalid as soon as step(...) ends. Line 53 doesn't make it anyway better...
Also, just wanted to say, don't start identifiers or macros with 2 underscores (e.g. __DEAD__) or one underscore followed by a capital letter. They are reserved by the standard.
@coder777
I'm calling a join() for each thread at line 42, so there's no reason the function ends before threads. Or maybe I missunderstood what you wanted to say.
@Ganado
Thank you for the tip, I though underscores where some kind of convention of naming.