Access violation C++ (Deleting items in a vector)
- by Gio Borje
I'm trying to remove non-matching results from a memory scanner I'm writing in C++ as practice. When the memory is initially scanned, all results are stored into the _results vector.
Later, the _results are scanned again and should erase items that no longer match.
The error:
Unhandled exception at 0x004016f4 in
.exe: 0xC0000005: Access
violation reading location 0x0090c000.
// Receives data
DWORD buffer;
for (vector<memblock>::iterator it = MemoryScanner::_results.begin(); it != MemoryScanner::_results.end(); ++it) {
// Reads data from an area of memory into buffer
ReadProcessMemory(MemoryScanner::_hProc, (LPVOID)(*it).address, &buffer, sizeof(buffer), NULL);
if (value != buffer) {
MemoryScanner::_results.erase(it); // where the program breaks
}
}