异常的 std::map 运行时错误

发布于 2024-07-25 14:25:37 字数 1413 浏览 3 评论 0原文

我正在为我正在开发的游戏编写一个编辑器,作为该编辑器的一部分,显然我需要有纹理。 我已经创建了一个 std::map 变量,

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

在我的图像加载代码中,我有以下代码片段。

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;

现在,由于某种原因,我在尝试使用上述代码后收到运行时错误。 一个访问冲突错误,在调试时,将我指向 std::map 代码本身,特别是这部分:

_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
    }

我只对图像加载函数进行一次调用,只是为了测试系统。 我检查了变量,文件名和 id 变量都是正确的。 关于可能导致运行时崩溃的任何想法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文