Page 1 of 1

READ: error in invalid memory area what does that mean?

PostPosted: Tue Jul 28, 2009 7:45 pm
by jimmynewguy
I keep getting a run time error on line 28, i've tried everything i know how to but no result..... can anyone help me? the code is here and if you don't know how to fix it can anyone tell me what it means? Thanx. The code is to get the closest enemy1 and set the targetx and targety as their x2 & y2. I marked line 28
Code: Select all
int n;
double mindist = 100;
actors = getAllActorsInCollision("Event Actor", &n);


if(actors)
{
  int i;
  for(i = 0; i < n; i++)
  {
    if(strcmp(actors[i].name, "enemy1") == 0)
    {
       double d = distance(parent.x, parent.y, actors[i].x2, actors[i].y2);
       if(d < mindist)
       {
           closest = (actors + i);
           mindist = d;
       }
    }
  }
}
if(!closest)
{
targetx = -500;
targety = 3000;
}
else if(closest)
{
targetx = closest->x2;//LINE 28 IS THIS ONE
targety = closest->y2;//WHY NO ERROR HERE?
}

targetx = closest->x2; again for anger lol

Re: READ: error in invalid memory area what does that mean?

PostPosted: Tue Jul 28, 2009 8:19 pm
by makslane
Try put:

Code: Select all
closest = NULL;


before your code

Re: READ: error in invalid memory area what does that mean?

PostPosted: Tue Jul 28, 2009 8:24 pm
by jimmynewguy
Code: Select all
Actor *actors, *closest = NULL;

i had that in global, but it works in code thanx mak, looks like i own you one....again :) It's kind of ironic that you helped me right that original code....