I am trying to invoke the clear() method on a std::map without getting an "Exception thrown: read access violation._Pnode was 0xDDDDDDDD.".
//I have narrowed down the error to this group of code
#include "stdafx.h"
#include <map>
#include <iostream>
class Input
{
std::map<int, bool> pressedKeys;
std::map<int, bool> heldKeys;
std::map<int, bool> releasedKeys;
public:
void Update()
{
heldKeys.clear();
pressedKeys.clear();
releasedKeys.clear();
}
};
class Window
{
private:
Input * input;
void Update()
{
input->Update();
}
public:
Window()
{
input = &Input();
while (true)
{
this->Update();
}
}
};
int main()
{
Window w = Window();
}
The exception always happens on "heldKeys.clear();" The debugger in Visual Studio brings me to a page called "xtree." The code that follows is the code around where the exception happens in "xtree:"
void _Erase(_Nodeptr _Rootnode)
{ // free entire subtree, recursively
for (_Nodeptr _Pnode = _Rootnode; !_Pnode->_Isnil; _Rootnode = _Pnode) //The error occurs here
{ // free subtrees, then node
_Erase(_Pnode->_Right);
_Pnode = _Pnode->_Left;
_Alnode& _Al = this->_Getal();
_Alnode_traits::destroy(_Al, _STD addressof(_Rootnode->_Myval));
_Node::_Freenode0(_Al, _Rootnode);
}
}
I expect no exceptions. I am getting the exception "Exception thrown: read access violation. _Pnode was 0xDDDDDDDD." If any more clarification is needed please comment.