My project compiles fine, but when running a push_back on a vector, I'm getting an access violation when the vector attempts to resize itself. I have lots of code, but hopefully I can boil it down to just relevant classes.
I am sorry about the HUGE amount of code, but I want my example to be compilable, and the error is likely some sort of copy constructor or assignment operator error and not the immediate use of vector, the error appears when line 513 of parsetokenizer.cpp runs during the third loop through the main function. It happens when the vector re-sizes itself it calls a method called _Orphan_all() which causes the access violation Unhandled exception at 0x6d8cad54 (msvcp100d.dll) in FloatingTests.exe: 0xC0000005: Access violation writing location 0x00000065.
> msvcp100d.dll!std::_Container_base12::_Orphan_all() Line 202 + 0x5 bytes C++
FloatingTests.exe!std::vector<parse::Token,std::allocator<parse::Token> >::reserve(unsigned int _Count) Line 768 + 0xb bytes C++
FloatingTests.exe!std::vector<parse::Token,std::allocator<parse::Token> >::_Reserve(unsigned int _Count) Line 1298 C++
FloatingTests.exe!std::vector<parse::Token,std::allocator<parse::Token> >::push_back(const parse::Token & _Val) Line 992 C++
FloatingTests.exe!parse::TokenStringSource::nextVector() Line 514 C++
FloatingTests.exe!parse::TokenStringSource::loadChache() Line 531 + 0xc bytes C++
FloatingTests.exe!parse::TokenStringSource::ensureChacheIsLoaded() Line 545 C++
FloatingTests.exe!parse::TokenStringSource::hasMoreTokenStrings() Line 540 C++
FloatingTests.exe!TokenStringSourceExample::operator()(char * * argv, int argc) Line 188 + 0xb bytes C++
FloatingTests.exe!main(char * * argc, int argv) Line 40 + 0x31 bytes C++
FloatingTests.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
FloatingTests.exe!mainCRTStartup() Line 371 C
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
std::string s = "I came; I saw; I left in peace;";
Again sorry about the codes size, anything you can see that could be the problem would be helpful. Runtime errors like this drive me crazy and I always have trouble figuring out where the real problem is.
Without looking at your code (because let's be fair, there's a lot of it), my gut reaction is that you've done something somewhere that corrupted the vector. This is most likely due to an out of range access or wayward pointer. So in troubleshooting I'd focus on memory corruption.
Can you shrink your code down to bare bones without eliminating the error? That would be mighty helpful both to us and to you. ;)
Can you shrink your code down to bare bones without eliminating the error? That would be mighty helpful both to us and to you.
I don't know, the code is quite intertwined so omitting any causes most to stop compiling, but I can give you the snippet that actually fails. I don't know what could be corrupting the memory, the vector is function local and it's storing the full object, and not pointers. The function during which the error occurs is:
Token tok = tokenizer.nextToken();
v.push_back(tok);//IN THIS CALL THERE IS AN ACCESS VIOLATION
two calls to the above function succeed, and the third creates the longest vector (4 items), and on the fourth call to push_back, somewhere deep within the resize, a call to _Orphan_all() causes an access violation (stack trace in OP)
but I can give you the snippet that actually fails
Well, the vector itself is a local variable, so that helps. Try tracing nextToken(), the constructor for Token(), type(), and strval() to see what kind of memory accesses are happening. You might be dereferencing a dangling pointer or an array out of bounds, or something.