glGenBuffers returns 0xffffffff as buffer name

2019-08-06 05:47发布

I have the following code (OpenglES2.0 on iphone):

glGenBuffers(1, &tmp->m_vbo);

where tmp->m_vbo is unsigned int.

For most of the time tmp->m_vbo is valid and everything works perfect, but sometimes the returned value is 0xffffffff and first time I try to use that vbo will crash in glDrawElements.

Anyone knows what might cause this ?

Thanks.

3条回答
在下西门庆
2楼-- · 2019-08-06 05:51

I found the cause: there seemed to be something with the context. I used two threads, a loading thread and the main thread, each with each context (shared data). I had a "current context" value that I was checking before setting the required context (to avoid redundant SetContext calls) and somehow my "current context" value was set to the correct context, but the actual context in EAGLView was not. The fix was to use currentContext from EAGLView for tests instead of my own value.

查看更多
放荡不羁爱自由
3楼-- · 2019-08-06 06:03

This return value is a -1. You should check GL error after glGenBuffers.

查看更多
趁早两清
4楼-- · 2019-08-06 06:12

I had the same issue!

In Swift:

func updateContext() {
    if glContext != EAGLContext.currentContext() {
        EAGLContext.setCurrentContext(glContext)
    }
}

Using updateContext() function right before a problem place in code solved my problem.

查看更多
登录 后发表回答