swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] Segmentation Violation


From: Alex Olivas
Subject: Re: [Swarm-Support] Segmentation Violation
Date: Mon, 25 Oct 2004 18:54:08 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913

Steve Railsback wrote:

Alex Olivas wrote:

I modified bug slightly to "interact" with nearest neighbor bugs.
I would like for an individual bug's step to depend on the state
of the bugs around it.  I defined a simple method called getRole,

- (int)getRole;
{
 return role;
}

My code compiles just fine, but when I run it crashes in the
bug's step method at the line...

int neighborRole = [[world getObjectAtX: xPos+deltaX Y: yPos+deltaY] getRole];


One thing to check very carefully is whether (xPos+deltaX) or (yPos+deltaY) could ever exceed the size of world. If they do, I think you'll get a segmentation fault.

Steve R.

That actually turned out to be the problem. I thought it odd that if the position were off the grid [world getObjectAtX: xPos+deltaX Y: yPos+deltaY] would return a non-nil value.
The line just before the one above checks this...

if([world getObjectAtX: xPos+deltaX Y: yPos+deltaY]!= nil){
     //printf("x: %d y: %d\n",xPos+deltaX,yPos+deltaY);
     //xprint([world getObjectAtX: xPos+deltaX Y: yPos+deltaY]);
int neighborRole = [[world getObjectAtX: xPos+deltaX Y: yPos+deltaY] getRole];

Thanks,
Alex.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]