Xcode frame capture fails

I am using Xcode 4.5.1 and testing on iPhone5 with iOS6.

I used the frame capture function without problems, but suddenly it stopped working. When I press the capture button, the frame seems to be captured and the phone switches to a blank screen, only to suddenly switch back to the application screen and the application continues to work. I can still debug and pause the application, but there is no way to get frame capture. I also do not see errors in the console.

The reason it stopped working is because part of the code. This code should display something in the rendertexture, but the rendertexture seems empty. I wanted to use the frame capture function to find out what was wrong, but the code itself would not let me capture ... :(

Any idea why?

// ------------- init function ----------------- // Create the framebuffer and bind it glGenFramebuffers(1, &g_framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, g_framebuffer); //Create the destination texture, and attach it to the framebuffer's color attachment point. glGenTextures(1, &g_texture); glBindTexture(GL_TEXTURE_2D, g_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_texture, 0); //Test the framebuffer for completeness GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER) ; if(status != GL_FRAMEBUFFER_COMPLETE) { NSLog(@"failed to make complete framebuffer object %x", status); } else { NSLog(@"SkyPlugin initialized"); } // ----------------- on update ------------------ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO); glGetIntegerv(GL_VIEWPORT, oldViewPort); // set the framebuffer and clear glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, g_framebuffer); glViewport(0, 0, 32, 32); //glClearColor(0.9f, 0.1f, 0.1f, 1.0f); glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT); // Set shader glUseProgram(m_program); // do some glEnableVertexAttribArray // ... // texture setting glActiveTexture(GL_TEXTURE0); glUniform1i(m_uniform, 0); ResourceManager* resourceManager = ResourceManager::GetInstance(); glBindTexture(GL_TEXTURE_2D, m_texture[0]); // ----------- Draw ----------- // Draws a full-screen quad to copy textures static const vertexDataUV quad[] = { {/*v:*/{-1.f,-1.f,0}, /*t:*/{0,0}}, {/*v:*/{-1.f,1,0}, /*t:*/{0,1}}, {/*v:*/{1,-1.f,0}, /*t:*/{1,0}}, {/*v:*/{1,1,0}, /*t:*/{1,1}} }; static const GLubyte indeces[] = {0,2,1,3}; glVertexAttribPointer(m_posAttrib, 3, GL_FLOAT, 0, sizeof(vertexDataUV), &quad[0].vertex); glVertexAttribPointer(m_texCoordAttrib, 2, GL_FLOAT, 0, sizeof(vertexDataUV), &quad[0].uv); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indeces); // ------------ End // go back to the main framebuffer! glBindFramebuffer(GL_FRAMEBUFFER, oldFBO); glViewport(oldViewPort[0], oldViewPort[1], oldViewPort[2], oldViewPort[3]); glEnable(GL_DEPTH_TEST); //glClearColor(0.1f, 0.1f, 0.1f, 1.0f); 

Edit: (2012 / October / 28)

I found out why the above code did not work. I forgot to link the render buffer! The code below works, but the frame capture does not work when this code is active ...

On init

// Create a rendering buffer and bind it to glGenRenderbuffers (1, & g_renderbuffer); glBindRenderbuffer (GL_RENDERBUFFER, g_renderbuffer); glRenderbufferStorage (GL_RENDERBUFFER, GL_RGBA8_OES, w, h);

 // Create the framebuffer and bind it glGenFramebuffers(1, &g_framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, g_framebuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, g_renderbuffer); //Create the destination texture, and attach it to the framebuffer's color attachment point. glGenTextures(1, &g_texture); glBindTexture(GL_TEXTURE_2D, g_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_texture, 0); 

When updating

 glGetIntegerv(GL_RENDERBUFFER_BINDING, &oldRBO); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO); glGetIntegerv(GL_VIEWPORT, oldViewPort); // set the framebuffer and clear glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, g_framebuffer); glBindRenderbuffer(GL_RENDERBUFFER, g_renderbuffer); glViewport(0, 0, 32, 32); // ... draw stuff ... 

End of update,

 // go back to the main framebuffer! glBindFramebuffer(GL_FRAMEBUFFER, oldFBO); glBindRenderbuffer(GL_RENDERBUFFER, oldRBO); 
+6
source share
2 answers

It seems to have been an Xcode bug. The latest version of Xcode 4.5.2 allows me to capture a frame :)

After capturing the frame, I get an error message in this part of the code:

 // ... draw stuff ... glActiveTexture(GL_TEXTURE0); glUniform1i(MY_TEXTURE, 0); 

In glUniform1i I get this error: "The specified operation is not valid for the current state of OpenGL."

I don’t know why I am getting this error (rendering it works), but I suspect that this error may be the reason that I could not capture the frame in the previous version of Xcode ...

+2
source

I saw a very similar behavior, and although it was a little unstable, it seems to be related to memory usage. Usually, when this failed, the playback application seems to run out of memory (I will see a warning about saving memory in the console when it failed).

Switching to a device with more memory fixed it (iPad 4 from iPad 3), but I could also sometimes bypass it by reducing the amount of texture memory used - skipping the upper mipmap setting for all my textures usually frees up enough.

0
source

All Articles