
June 5th, 2007, 09:54 AM
|
|
Registered User
|
|
Join Date: May 2004
Posts: 2
Time spent in forums: 18 m 32 sec
Reputation Power: 0
|
|
|
Trouble invoking method on object returned from NSEnumerator
Hey all,
I'm relatively new to Obj-C, so please bear with me. What I have is a problem where my program crashes when I attempt to invoke a method on an object, but only after it comes out of an NSEnumeration.
The problem occurs when I attempt to invoke [worldLoc x] in the code below. When I invoke this on the object before it goes into the array, it works fine, but after it crashes and brings up the debugger with the stack trace shown after the code below.
Any ideas would be appreciated,
Wil
Code:
- (void)drawRect: (NSRect) drawRect
{
NSEnumerator *e = [world entityEnumerator];
WorldEntity *entity;
int radius = 2;
float minX = -10.0f;
float maxX = 10.0f;
float minY = -10.0f;
float maxY = 10.0f;
NSPoint location;
NSRect rect;
while (entity = [e nextObject])
{
Vector2D *worldLoc = [entity location];
NSRect bounds = [self bounds];
float pctX = ([worldLoc x] - minX) / (maxX - minX);
if (pctX >= 0.0 && pctX <= 100.0)
{
float pctY = ([worldLoc y] - minY) / (maxY - minY);
if (pctY >= 0.0 && pctY <= 100.0)
{
location.x = bounds.size.width * pctX;
location.y = bounds.size.height * (1 - pctY);
[self circleRectAt: location withRadius: radius rect: &rect];
[[NSBezierPath bezierPathWithOvalInRect: rect] fill];
}
}
}
}
Code:
objc_msgSend_fpret
??
-[NSView _drawRect:clip:]
.
.
.
I believe the ?? is my drawRect method. When I run it through the debugger, it crashes when I try to step into [worldLoc x].
|