Unusual std :: map runtime error

I'm hacking the editor for the game I'm working on, and as part of this editor, I need to have textures, obviously. I created the std :: map variable so

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

In my image upload 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 trying to use the above code. An access violation error that during debugging points to the std :: map code itself, in particular, this part:

 _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 only make one call to the image upload function just to check the system. I checked the variables and the file names and identifiers are correct. Any ideas on what could lead to a runtime failure?

+4
source share
1 answer

It seems that the map was not built properly. The initialization order is probably incorrect. Is the map static or global? Is your code part of a static object?

+1
source

Source: https://habr.com/ru/post/1286718/


All Articles