iOS GL ES exc_bad_access on glDrawElements
iOS GL ES exc_bad_access on glDrawElements
我正在尝试使用Assimp和gl es制作一个小型应用程序,该应用程序在iOS上加载并呈现模型。我以前曾与OpenGL合作,但未与GLES合作;而且iOS上从来没有任何东西。
目前,我在调用gldrawelements时会遇到exc_bad_access错误;我看不到我在做什么错。
这是我的顶点类型:
typedef struct {
float Position[3];
} Vertex;
这是我的网格类型:
class Mesh {
public:
Vertex* vertices;
GLuint verticesCount;
GLubyte* indices;
GLuint indicesCount;
std::vector<Texture> textures;
GLuint vertexBuffer, indexBuffer;
Mesh(Vertex* vertices, GLubyte* indices, std::vector<Texture> textures);
};
我非常有信心,我像以前那样通过Assimp正确地加载模型,并从另一个项目中提起此代码。因此,我正在使用该数据传递到网格构造函数,并且我正在使用此数据填充VBO:
glGenBuffers(1, &this->vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer);
int sizeOfVerts = sizeof(Vertex) * this->verticesCount;
std::cout << "Size of verts in bytes " << unsigned(sizeOfVerts) << std::endl;
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)sizeOfVerts, &this->vertices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &this->indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer);
int sizeOfInd = sizeof(GLubyte) * this->indicesCount;
std::cout << "Size of inds in bytes " << unsigned(sizeOfInd) << std::endl;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)sizeOfInd, &this->indices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
使用预测和查看模型矩阵已经在预渲染函数中设置了
- (void)renderMesh:(Mesh*)mesh
{
glBindBuffer(GL_ARRAY_BUFFER, mesh->vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->indexBuffer);
glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
int meshSize = mesh->indicesCount;
glDrawElements(GL_TRIANGLES, meshSize, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
_positionSlot是我的着色器中的属性位置。我知道我的着色器工作起作用,因为我已经用它来绘制无聊的平方等等 - 因此,错误肯定是在上述代码中 - 某处。
预先感谢,我会确保我既投票又接受:)
发生这种情况的原因是因为我将glubyte用于索引类型;对于我的高层模型来说太小了。不确定为什么该错误在此错误消息中表现出来;在其他平台上,相同的代码将渲染垃圾模型。也许是特定于iOS的?希望这可以帮助别人。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 循环挂起迭代的 std::擦除 on std::list
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- std::bind on statd::array 的运算符 []
- 将数组信息存储到 c++ 向量中有一个"Access violation reading location"
- 您将如何连接"on the fly"文本+整数并将其传递给函数?
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- VS2019 - Sudo Remote Debugging on Linux with Cmake project
- 为什么调试器引发"read access violation. this was nullptr"异常?
- 在 Microsoft Access SQL 中调用自定义 DLL 函数时传递的内存地址无效
- C++ library with Tensorflow on Android
- SFML 交叉编译 for Windows on Linux.
- How to recover system gcc compiler on centos 6
- Cmake with Flex/Bison on windows
- Simulink "Access Violation"写入 C++ lambda 函数捕获列表中的 PWork 变量
- 按原样保存用户输入 - Ruby on Rails
- OpenAL C++ on Linux
- Boost::process on Windows - with MinGW?
- Qt QXmlStreamReader Access Violation