`-drawInRect` seems to be different in 10.11?

Edit: Filed a Radar: # 21941373
We have an app that works in 10.10, but has this issue in 10.11.
We call `-drawRect` in a `NSGraphicsContext` on an `NSImage` that is properly set in both OS


But in 10.11 this `NSImage` doesn't get drawn.


I'm pretty novice, but I have been debugging for quite a while to get to where I'm at now, and I'm just plain stuck. Was seeing if anybody ran into this before, or has any idea why this could be.

Here is the pertinent code:
(the `layer` object is a `CGLayerRef` that is passed into this method, from the `-drawRect` method)
Here is how the layer is instantiated:


NSRect scaledRect = [Helpers scaleRect:rect byScale:[self backingScaleFactorRelativeToZoom]];

   CGSize size =  NSSizeToCGSize(rect.size);
size_t width = size.width;
size_t height = size.height;
size_t bitsPerComponent = 8;
size_t bytesPerRow = (width * 4+ 0x0000000F) & ~0x0000000F; /
size_t dataSize = bytesPerRow * height;
   void* data = calloc(1, dataSize);

CGColorSpaceRef colorspace = [[[_imageController document] captureColorSpace] CGColorSpace];
CGContextRef bitmapContext = CGBitmapContextCreate(data, width, height, bitsPerComponent, bytesPerRow, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
   CGLayerRef canvasLayer = CGLayerCreateWithContext(bitmapContext, scaledRect.size, NULL);



Here is the method that draws the image:


CGContextRef mainLayerContext = CGLayerGetContext(layer);
   NSRect scaledBounds = [contextInfo[kContextInfoBounds] rectValue];
   if( !_flatCache )
   {
      _flatCache = CGLayerCreateWithContext(mainLayerContext, scaledBounds.size, NULL);
      CGContextRef flatCacheCtx = CGLayerGetContext(_flatCache);

      CGLayerRef tempLayer = CGLayerCreateWithContext(flatCacheCtx, scaledBounds.size, NULL);
      CIImage *tempImage = [CIImage imageWithCGLayer:tempLayer];
      NSLog(@"%@",tempImage);
      CGContextRef tempLayerCtx = CGLayerGetContext(tempLayer);

      CGContextTranslateCTM(tempLayerCtx, -scaledBounds.origin.x, -scaledBounds.origin.y);

      [NSGraphicsContext saveGraphicsState];
      NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphicsPort:tempLayerCtx flipped:NO];
      [NSGraphicsContext setCurrentContext:newContext];

      if ( [_imageController background] )
      {
         NSRect bgRect = { [_imageController backgroundPosition], [_imageController backgroundSize] };
         bgRect = [Helpers scaleRect:bgRect byScale:[self backingScaleFactorRelativeToZoom]];
         [[_imageController background] drawInRect:bgRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
      }

      CIImage *tempImage2 = [CIImage imageWithCGLayer:tempLayer];
      NSLog(@"%@",tempImage2);


In 10.10 and 10.11, tempImage is an empty image w/ the correct size.
In 10.10 tempImage2 now has `[_imageController background]` properly drawn
In 10.11 tempImage2 is the same as tempImage, a blank image w/ the correct size


bgRect is not the issue, already tried modifying that around. I have also messed with the `-translate` arguments, but still couldn't learn anything.


Does anybody know how else I could debug this to find the issue? Or better yet, has anybody seen this issue and know what my problem is?

Replies

I am having the same issue. In effect, I have traced the issue down to[NSGraphicsContext currentContext] returning nil in the drawRect: method, which I am certain is a bug. Most of our draw methods are broken, yet the very same code works on OS X 10.11 having been compiled with an older SDK. Setting the CGPostError breakpoint stops in Apple's code. Very frustrating that there's nothing I can do at the moment.

I've seen this too. [NSGraphicsContext currentContext] returns nil when compiled with 10.11. Anyone make progress on this?

Are you guys calling `-drawRect:`, as opposed to just implementing it and letting the framework call it? If so, then that's the problem.