I am getting a seg fault from some code which accesses an array consisting of strings. The odd thing is I lose the memory across a one-line function call.
So this is my code:
class A {
void method1(){
std::cout << _myArray[ID] << std::endl; //This outputs fine
_pointerToObjectB->method2(ID, side);
}
std::array<std::string, 30000> _myArray;
B* _pointerToObjectB;
};
In a different class:
class B {
void method2(const int16_t ID, const int8_t Side) {
std::cout << _objectA._myArray[ID] << std::endl; //Seg fault
}
A _objectA;
};
GDB reports a seg fault, backtrace:
#0 0x00007ffff05cd81c in std::string::_M_data() const () from /debug/bin/../lib/libstdc++.so.6
#1 0x00007ffff05cd85a in std::string::_M_rep() const () from /debug/bin/../lib/libstdc++.so.6
#2 0x00007ffff05cdeb8 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) ()
from /debug/bin/../lib/libstdc++.so.6
#3 0x00007fffe32f8bb1 in B<(short)-2, (short)1, (short)30000>::method2 (this=0x0, ID=362, Side=0 '\000')
#4 0x00007fffe32eafdf in A<(short)-2, (short)1, (short)30000>::method1 (this=0x2754400, ID=362, Side=0 '\000')
The pointer must be fine as it was able to invoke method2(). What else could be wrong?!
Its as if _objectA has been deleted across the call?
This seg fault is consistent, it happens every time I run the program. I'm at a bit of a loss what to do next.
Aucun commentaire:
Enregistrer un commentaire