glGenBuffers returns 0xffffffff as buffer name

2019-08-06 05:32发布

问题:

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.

回答1:

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.



回答2:

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.



回答3:

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