glDrawArray() 给出内存异常
在循环遍历我想要在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是您的问题
mesh(0)
。也许您在初始化该值之前调用了Draw()
方法。也许您的 Renderer 类可以做到这一点。尝试在任何函数调用之前添加
assert(mesh != 0)
。我希望您正在检查 GL_ARB_vertex_buffer_object 是否可用。我希望这能起作用。
I think here is your problem
mesh(0)
. Maybe you are calling theDraw()
method before you initialize this value. Maybe yourRenderer
class does it.Try to add
assert(mesh != 0)
before any function call.And I hope, that you are checking, if
GL_ARB_vertex_buffer_object
is available. I hope this works.