NSRect parameter is 'ignored' in Objective-C code

Hi all -


never seen this before. In my Objective-C printing code this happens:


  1. OS printing framework calling drawRect: with proper dirtyRect parameter
  2. My internal function [drawStuff:(NSRect)localRect] is called with dirtyRect as parameter
  3. In drawStuff: the value of the localRect parameter is uninitialized containing random floating point values..
    (going up 1 stack frame all looking great)


This is the debug build of course.

As far as I can tell this only happens when the code is called during printing.


ANY ideas what's going on??


Cheers,

Jay

Replies

Show some actual code. At least the declaration of the view's -drawRect: method and how it calls -drawStuff: and the method header of -drawStuff:. If -drawStuff: is declared anywhere separately from the implementation, show both.


Are you sure you don't have an actual local variable (not the method parameter) called "localStuff" that might be hiding the parameter? Have you turned on most warnings and are there any warnings for this code?

Silly errors have been eliminated - this works most of the time but breaks at some point during printing..


- (void) drawWithScaleFactor:(double)scaleFac dirtyRect:(NSRect)dirtyRect

{

__block NSRect localDirtyRect = dirtyRect,

localGridRect = self.renderData.gridRect;


dispatch_sync(self.accessQueue,

^{

[[NSColor whiteColor] setFill];

NSRectFill(localDirtyRect);


double spacing = fmax(self.renderData.gridSpacing, 1.0);


// VALID RECTS HERE

[PrivatePainter drawGridInRect:localGridRect

dirtyRect:localDirtyRect

withScaleX:scaleFac

scaleY:scaleFac

gridSpacing:spacing

color:self.renderData.gridColor];

});

}


Stepping into PrivatePainter all rect params are garbage.


Cheers,

Jay