• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem on clearing points and paths on a NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem on clearing points and paths on a NSView


  • Subject: Re: Problem on clearing points and paths on a NSView
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 22 Jul 2008 22:50:30 -0700

On Jul 22, 2008, at 18:45, JArod Wen wrote:

drawRect:

-(void)drawRect:(NSRect)rect
{
	[self renderCurrentFrame];
}

As both Graham and Jens said, drawRect has to draw *everything* in 'rect', including the background fill (which effectively erases what you drew the last time through). Currently, you're just drawing on the top of whatever happens to be in the view at the time 'drawRect' is called.


and renderCurrentFrame:


- (void)renderCurrentFrame { if(isMeasured) switch (measureMethod) { case 0: [self renderPoint:singlePoint]; break; case 1: [self renderPath:pathForDistanceMeasure]; break; case 2: [self renderPath:pathForAngleMeasure]; break; case 3: [self renderPath:selectedPath]; break; default: break; } [self needsDisplay];

This '[self needsDisplay]' shouldn't be here. It's just an accessor, so it doesn't actually do anything. If you meant to write '[self setNeedsDisplay: YES]', that would be worse -- you should never manipulate the needsDisplay state of a view from within drawRect or any method it calls.


   }

and renderPoint:

- (void)renderPoint:(NSPoint)pointLoc
{
   [pathForPositionMeasure appendBezierPathWithArcWithCenter: pointLoc
	  radius: BLOB_SIZE / 2.0
	  startAngle: 0.0
	  endAngle: 360.0];

   [[NSColor blackColor] set];
   [pathForPositionMeasure fill];
   [[NSColor whiteColor] set];
   [pathForPositionMeasure stroke];
}

The first line doesn't look right. Every time you redraw the view, you're adding another point to 'pathForPositionMeasure' and in particular you'll add the same point over and over again if the view is redrawn without the data actually changing. (Unless this is all managed properly elsewhere.)


and renderPath:

- (void)renderPath:(NSBezierPath *)pathForRender
{
	int i = 0;
	float lineDash[3];
	lineDash[0] = 3.0;
	lineDash[1] = 2.0;
	lineDash[2] = 3.0;

for(i=0; i < [pathForRender elementCount]; i++){
NSPoint elementPoint[3];
NSBezierPathElement element;
element = [pathForRender elementAtIndex:i associatedPoints:elementPoint];
NSBezierPath *pathPoint = [[NSBezierPath alloc] init];


		[pathPoint appendBezierPathWithArcWithCenter: elementPoint[0]
			radius: BLOB_SIZE / 2.0
			startAngle: 0.0
			endAngle: 360.0];
		[[NSColor blackColor] set];
		[pathPoint fill];
		[[NSColor whiteColor] set];
		[pathPoint stroke];
	}
	[[[NSColor whiteColor] colorWithAlphaComponent:0.5] set];
	[pathForRender fill];
	[[NSColor blackColor] set];
	[pathForRender setLineWidth:1.0];
	[pathForRender setLineDash:lineDash count:3 phase:0.0];
	[pathForRender stroke];
}

Yes, you're leaking a NSBezierPath in every iteration of the loop (unless you're using garbage collection). You can just add a '[pathPoint release]' as the last statement inside the loop.


Now I am considering the possible memory leakage in renderPath, since each time the path will be initialized and the previous one will cause memory leakage, which may be also the reason why I cannot get rid of them from the view. But if so, how about the renderPoint? It seems ok but still cannot be removed...

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Problem on clearing points and paths on a NSView (From: JArod Wen <email@hidden>)
 >Re: Problem on clearing points and paths on a NSView (From: Jens Alfke <email@hidden>)
 >Re: Problem on clearing points and paths on a NSView (From: JArod Wen <email@hidden>)

  • Prev by Date: Re: Returning exactly what has been promised
  • Next by Date: Re: NSConnection Issue
  • Previous by thread: Re: Problem on clearing points and paths on a NSView
  • Next by thread: CA: Are nested 3D transforms supported?
  • Index(es):
    • Date
    • Thread