使用glVertexAttrib3f在glDrawArrays上崩溃
Crash on glDrawArrays with glVertexAttrib3f
我在glDrawArrays上看到了很多其他与EXC_BAD_ACCESS信号相关的帖子,但没有一个完全符合我的问题,所以就这样吧。
以下代码有效:
glEnableVertexAttribArray(mAttributes.position);
glEnableVertexAttribArray(mAttributes.color);
GLsizei stride = sizeof(Vertex);
const GLvoid* pPos = &mVertices2[0].mPos.x;
const GLvoid* pColors = &mVertices2[0].mColor.r;
glVertexAttribPointer(mAttributes.position, 2, GL_FLOAT, GL_FALSE, stride, pPos);
glVertexAttribPointer(mAttributes.color, 3, GL_FLOAT, GL_FALSE, stride, pColors);
glDrawArrays(GL_LINE_STRIP, 0, mVertices2.size());
但我似乎不能用一个不变的属性来书写颜色。这在glDrawArrays上崩溃:
glEnableVertexAttribArray(mAttributes.position);
glEnableVertexAttribArray(mAttributes.color);
glVertexAttribPointer(mAttributes.position, 2, GL_FLOAT, GL_FALSE, stride, pPos);
glVertexAttrib3f(mAttributes.color, 1.0f, 0.0f, 0.0f);
glDrawArrays(GL_LINE_STRIP, 0, mVertices2.size()); // <-- EXC_BAD_ACCESS because of the line above
有人知道为什么吗?是否只能使用glDrawElements
的常量顶点属性调用?
您告诉OpenGL使用VertexAttribArray,然后您就不提供数组元素了。因此,OpenGL将尝试读取既没有分配也没有正确填充的内存。一定要做
glDisableVertexAttribArray(ARRAYINDEX)
当您不提供特定数组的数据时。只使用glVertexAttrib3f()
是可以的。但它不是一个数组,所以不需要启用数组就可以使用它。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- 程序崩溃并显示"std::out_of_range"错误
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 为什么我的多线程作业队列崩溃
- ExtractIconEx:可以工作,但偶尔会崩溃
- 为什么引用传递会导致此崩溃(C++)
- 试图创建流或fopen时程序崩溃
- 类对象数组的问题会导致崩溃
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 为什么要增加导致崩溃的指针
- 在虚幻引擎中删除NXOpen对象时崩溃
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 使用glVertexAttrib3f在glDrawArrays上崩溃
- 在大型模型的glDrawArrays中崩溃