CGBitmapContextCreateImage - vm_copy failed - iPhone SDK

后端 未结 1 1940
悲&欢浪女
悲&欢浪女 2020-12-17 20:19

I am having an issue using CGBitmapContextCreateImage in my iPhone app.

I am using AV Foundation Framework to grab camera frames using this method:

-         


        
相关标签:
1条回答
  • 2020-12-17 20:31

    Disclaimer: this is pure speculation. Not anymore.

    vm_copy() is a kernel call to copy virtual memory from one place to another (manpage).

    The return value you get is KERN_PROTECTION_FAILURE, "The source region is protected against reading, or the destination region is protected against writing."

    So for some reason CGDataProviderCreateWithCopyOfData calls this to copy some memory, and fails. maybe it is just trying vm_copy as a fast method first, and then falls back to a slower method (since you say everything works).

    If you malloc a chunk of memory, memcpy the memory from baseAddress to your own memory, and use that to create the image, the warning vanishes. So:

    uint8_t *tmp = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
    int bytes = ... // determine number of bytes from height * bytesperrow
    uint8_t *baseAddress = malloc(bytes);
    memcpy(baseAddress,tmp,bytes);
    
    // unlock the memory, do other stuff, but don't forget:
    free(baseAddress);
    
    0 讨论(0)
提交回复
热议问题