2

When calling CGBitmapContextCreate method the app crashes giving EXC_BAD_ACCESS.

This happens only in iPhone 6+ (when running on on device).

CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);

And yes, I've tried setting NSZombieEnabled to YES as an environment variable.. but still nothing is getting displayed on the debugger console upon EXC_BAD_ACCESS.

Kampai
  • 22,848
  • 21
  • 95
  • 95
Gokul
  • 1,236
  • 1
  • 14
  • 26

1 Answers1

0

I was having a crash with this exact function because I was allocating a storage buffer with no respect to its alignment, e.g:

baseAddress = malloc (width * height * 4);

Now I use...

baseAddress = new u32 [width * height];

...to force a 4 byte alignment and it fixed the EXC_BAD_ACCESS. Note, I also use kCGBitmapByteOrder32Big instead of little as you are. May or may not be relevant.

However, I get weird pixel data back on an iPhone 6 and an iPad Mini.

(See Getting pixel data on iOS 8 / iPhone 6).

Community
  • 1
  • 1