glDrawArray() 给出内存异常

发布于 2024-11-02 19:44:12 字数 992 浏览 1 评论 0原文

在循环遍历我想要在 3D 引擎中渲染的所有对象时,尝试调用时出现错误

glDrawArrays(mesh->primitiveType, 0, mesh->vertexCount); 

,因为它尝试从位置 0x0000000 读取,因此显然绑定到 mesh->vertexBuffer 索引的指针指向零。这一切都发生在我的 RenderableObject 类中。此类的实例有一个与其绑定的网格,并且该网格包含应链接到 VertexArray 的索引。但显然

glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer);

是失败了。

奇怪的是,它可以在我的 mac 和其他各种 Windows 计算机上运行 - 但它不会在这台(Windows)计算机上运行。因为我正在测试,所以删除了所有 3D 模型,发现是原语导致了问题,MSVC++ 编译器以某种方式“优化”了我的代码,删除了之后的所有内容

glGenBuffers(1, &CubeMesh.vertexBuffer);

,这可能就是为什么没有任何内容绑定的原因,或者我是这么想的。我禁用了链接器/编译器优化,并且我可以看到所有断点现在都会被命中 - 但我仍然遇到相同的异常,并且我完全不知道为什么它不起作用。

该项目的完整源代码可以在 @ https://github.com/Wrap/TwinGame 找到/tree/master/src ,据我所知问题出在 Primitives.cpp 和/或 RenderableObject.cpp (特别是 RenderableObject::Draw(); 方法)文件中。我是否试图读取受保护的内容,LoadPrimitives(); 有什么问题吗?方法?

感谢您花时间阅读本文。

While looping through all objects I want to render in my 3D-engine, I get an error when trying to call

glDrawArrays(mesh->primitiveType, 0, mesh->vertexCount); 

Because it tries to read from location 0x0000000, so apparently the pointer bound to the mesh->vertexBuffer index points to zero. This all happens within my RenderableObject class. Instances of this class have a mesh bound to them, and this mesh contains an index that should link to the VertexArray. But apparently

glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer);

Is failing.

The strange thing is, that it will run on my mac, and various other windows computers - but it won't run on this (windows) computer. Because I'm testing I removed all 3D models, and found it's the primitives that are causing the problem, somehow the MSVC++ compiler "optimized" my code, to remove everything after

glGenBuffers(1, &CubeMesh.vertexBuffer);

And that's probably why nothing got bound, or so I thought. I disabled linker/compiler optimizations, and I could see allbreakpoints would get hit now - but I still get the same exception, and I'm absolutely clueless as to why it doesn't work.

The entire source of the project can be found @ https://github.com/Wrap/TwinGame/tree/master/src , as far as I can tell the problem is in the Primitives.cpp, and/or the RenderableObject.cpp (specifically the RenderableObject::Draw(); method) file. Am I trying to read something that is protected, what is wrong with the LoadPrimitives(); method?

Thanks for taking the time to read this.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-11-09 19:44:12
RenderableObject::RenderableObject(ObjectManager* objectmgr) : Object(objectmgr), visible(true), scale(1.0f), mesh(0) {
    mObjMgr->registerRenderable(this);
}

我认为这是您的问题mesh(0)。也许您在初始化该值之前调用了Draw()方法。也许您的 Renderer 类可以做到这一点。

尝试在任何函数调用之前添加 assert(mesh != 0)

void RenderableObject::Draw(class ShaderManager* shaderMgr){
    //TODO: iterate through all meshes that belong to the object

    assert(mesh != 0)

    glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer[0]);

我希望您正在检查 GL_ARB_vertex_buffer_object 是否可用。我希望这能起作用。

RenderableObject::RenderableObject(ObjectManager* objectmgr) : Object(objectmgr), visible(true), scale(1.0f), mesh(0) {
    mObjMgr->registerRenderable(this);
}

I think here is your problem mesh(0). Maybe you are calling the Draw() method before you initialize this value. Maybe your Renderer class does it.

Try to add assert(mesh != 0) before any function call.

void RenderableObject::Draw(class ShaderManager* shaderMgr){
    //TODO: iterate through all meshes that belong to the object

    assert(mesh != 0)

    glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer[0]);

And I hope, that you are checking, if GL_ARB_vertex_buffer_object is available. I hope this works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文