• 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
confused by signal error (newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

confused by signal error (newbie)


  • Subject: confused by signal error (newbie)
  • From: Daniel Child <email@hidden>
  • Date: Sun, 27 Feb 2005 22:27:00 -1000

Hi All,

I am working off of the ScratchPad tutorial and have set things up so that points are drawn along the path of the line drawn. That much works fine, but now I want to determine the angles between individual points. By adding two lines of code, I get a runtime error:

ScratchPad has exited due to signal 11 (SIGSEGV).

I've checked Kochan's book and reread the memory section and still can't see what I am doing wrong. The culprit lines are commented below. Would really appreciate and explanation of why it is wrong. Thanks in advance!

Daniel

- (void)drawRect:(NSRect)rect {

// VARIABLES
int count;
double frac, angle, rad, num, den;
Points *thisPoint, *lastPoint; // Points have x and y instance vars
NSEnumerator *ptsEnum;
NSMutableArray *pathAngles; // array of angles between path segments
NSNumber *angObject; // the angle as an object for use in array

// first draw the line
ptsEnum = [stroke objectEnumerator];
[[NSColor blueColor] set];
[path setLineWidth: 3];
[path stroke];
[[NSColor blackColor] set]; // the color for line points

// now add dots to show the points and calculate angles
if (stroke != nil) { // stroke is array created during mouseDragging
count = 0;
while ((thisPoint = [ptsEnum nextObject]) != nil) {
NSRectFill(NSMakeRect([thisPoint x], [thisPoint y], 5.0, 5.0));


if (count > 0) { // if not the first point
// CALCULATE THE ANGLE BETWEEN THIS POINT AND LAST POINT
[thisPoint print];
[lastPoint print];
num = [thisPoint y] - [lastPoint y];
den = [thisPoint x] - [lastPoint x];
frac = num/den;
rad = atan2(num, den);
angle = (rad * 360) / (2 * M_PI);
printf("the tan-theta is %f\n", frac);
printf("the atan in rads is %f\n", rad);
printf("the angle is %f\n\n", angle); // up to here everything works
angObject = [NSNumber numberWithDouble: angle]; // PROBLEM HERE
[pathAngles addObject: angObject]; // PROBLEM HERE
} // end inner if
count++;
lastPoint = thisPoint;
} // end while
} // end outer if
} // end method


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: confused by signal error (newbie)
      • From: Jeremy Dronfield <email@hidden>
  • Prev by Date: Re:Append to file with NSString writeToFile:
  • Next by Date: Re: Append to file with NSString writeToFile:
  • Previous by thread: Solved: How to call this Cocoa method from AppleScript?
  • Next by thread: Re: confused by signal error (newbie)
  • Index(es):
    • Date
    • Thread