Rendering to a gl texture from objective-c works in iOS4 but not iOS5

I’m trying to render the front-facing camera feed to the user. In iOS4 I have no issues, but in iOS5 the texture is invisible. When running on iOS5 this error appears in the console:

OpenGLES error 0x0502 in [** project path **]/xcode/Classes/iPhone_GlesSupport.cpp:204

In Unity I collect the texture ID with GetNativeTextureID and send to objective-c code

In Objective-C:

GLint texture, textureFilter;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &textureFilter);

glBindTexture(GL_TEXTURE_2D, feedbackTextureNativeId);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth, frameHeight, GL_BGRA, GL_UNSIGNED_BYTE, frameBGRAPrevious);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, textureFilter);
glBindTexture(GL_TEXTURE_2D, texture);

I’m using the same version of unity 3.4.2 and xcode 4.2, testing the code on two iPad2’s

I ended up fixing this by changing the rendering code to:

glBindTexture(GL_TEXTURE_2D, feedbackTextureNativeId);

    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, frameWidth, frameHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, frameBGRA );

The big difference being changing out glTexSubImage2D for glTexImage2D - no idea why the old way failed on iOS5, but it did.

OK, I seem to be running into the same issue, so I have a couple of questions. Are frameWidth and frameHeight powers-of-two? If not, which devices have you tested this on? It’s my understanding that you can only call glTexImage2D with non powers-of-two (NPOT) if the device supports the APPLE_texture_2D_limited_npot OpenGL ES extension. Based on http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/OpenGLESPlatforms/OpenGLESPlatforms.html#//apple_ref/doc/uid/TP40008793-CH106-SW1 it appears to me that only the PowerVR SGX-based platforms (i.e. iPhone 3GS and later, but only when running OpenGL ES 1.1) support this.