Unusual std::map runtime error

2019-02-23 06:19发布

I'm hacking together an editor for a game I'm working on and as part of that editor, I need to have textures, obviously. I've created a std::map variable as so,

std::map<std::string, unsigned int> textures;

In my image loading code, I have the following snippet.

unsigned int id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
glBindTexture(GL_TEXTURE_2D, 0);

textures[filename] = id;

Now for some reason, I get a runtime error after attempting to use the above code. An access violation error, that, when debugged, points me to the std::map code itself, specifically, this portion:

_Nodeptr _Lbound(const key_type& _Keyval) const
    {   // find leftmost node not less than _Keyval
    _Nodeptr _Pnode = _Root(); // ** this is the highlighted line **
    _Nodeptr _Wherenode = _Myhead;  // end() if search fails

    while (!_Isnil(_Pnode))
        if (_DEBUG_LT_PRED(this->comp, _Key(_Pnode), _Keyval))
            _Pnode = _Right(_Pnode);    // descend right subtree
        else
            {   // _Pnode not less than _Keyval, remember it
            _Wherenode = _Pnode;
            _Pnode = _Left(_Pnode); // descend left subtree
            }

    return (_Wherenode);    // return best remembered candidate
    }

I'm only making one call to my image loading function just to test the system. I checked the variables and both the filename and id variables are correct. Any ideas as far as to what could be causing the runtime crash?

0条回答
登录 后发表回答