ios - Memory leak when uploading an image to texture with CVOpenGLESTextureCacheCreateTextureFromImage -
i debugged instruments, cannot find it:
cvpixelbufferref pixelbuffer; cvreturn err = cvpixelbuffercreatewithbytes(kcfallocatordefault, image_width, image_height, kcvpixelformattype_32bgra, _outputframe.data, 4 * image_width, datareleasecallback, null, null, &pixelbuffer); if(!pixelbuffer || err) { nslog(@"cvpixelbuffercreatewithbytes failed (error: %d)", err); return; } cvopenglestexturecachecreatetexturefromimage(kcfallocatordefault, _backgroundtexturecache, pixelbuffer, null, gl_texture_2d, gl_rgba, image_width, image_height, gl_bgra, gl_unsigned_byte, 0, &_backgroundtextureref); _backgroundtexture = cvopenglestexturegetname(_backgroundtextureref); [_framelock unlock]; glbindtexture(gl_texture_2d, _backgroundtexture); gltexparameterf(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge); gltexparameterf(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge);
then in opengl draw method, after draw call:
... cfrelease(_backgroundtextureref); _backgroundtextureref = null; cvopenglestexturecacheflush(_backgroundtexturecache, 0);
i tried deallocate pixel buffer manually, fails in callback datareleasecallback
of cvopenglestexturecachecreatetexturefromimage
exc_bad_access
. don't know else leaking there.
update:
i commented out body of callback:
inline void datareleasecallback(void *releaserefcon, const void *baseaddress) { // free((void *)baseaddress); }
and can call:
cvpixelbufferrelease(_pixelbuffer);
without error , memory leak fixed. question arises utility of callback then?
ios objective-c memory-leaks opengl-es core-video
No comments:
Post a Comment