2
Guys I’m having a very annoying little problem, I’m implementing a simple A* . When I move the already checked item to the closed list and move the item from the open list, it is giving undeclared pointer error... That is the mistake pointer being freed was not allocated
, but I already checked my logic and also checked if I was dislocating a pointer that had actually been declared with malloc
and it really was! I even use it in the same code, another displacement code. I practically copied and pasted on each other and what was already done and no problem, but in the new gives... Look:
This is the code that’s working (I use this code to animate as well):
void anima(Lista* li, int frame, int agFramex, int agFramey){
Elem* no = (Elem*) malloc(sizeof(Elem));
Elem* ant = (Elem*) malloc(sizeof(Elem));
no = (*li);
ant = no;
while(no != NULL){
if(no->dados.y > ALT+200){
if(no == *li){
*li = no->Prox;
free(no);
no = *li;
} else if(no->Prox == NULL){
ant->Prox = no->Prox;
free(no);
no = ant->Prox;
} else {
ant->Prox = no->Prox;
free(no);
no = ant->Prox;
}
} else {
no->dados.y += no->dados.vel;
al_draw_bitmap_region(no->dados.Img, agFramex*frame, agFramey*frame, frame, frame, no->dados.x, no->dados.y, 0);
ant = no;
no = no->Prox;
}
}
}
That’s the code that’s not: (atual
and AbList
exist, are as function parameter up there, as the function was very extensive I chose not to put it whole here, in the previous moments of the function I put elements in the list just that):
Elc* rem = (Elc*) malloc(sizeof(Elc));
Elc* mer = (Elc*) malloc(sizeof(Elc));
rem = (*AbList);
mer = rem;
while(rem != NULL){
if(rem->dados.x == atual.dados.x && rem->dados.y == atual.dados.y){
if(rem == *AbList){
*AbList = rem->Prox;
free(rem);
rem = *AbList;
} else if(rem->Prox == NULL){
mer->Prox = rem->Prox;
free(rem);
rem = mer->Prox;
} else {
mer->Prox = rem->Prox;
free(rem);
rem = mer->Prox;
}
} else {
mer = rem;
rem = rem->Prox;
}
}
As you can see, the codes are very much the same, but for some reason in this I get the error and in the other...
Obs: Usage Macbook Pro I am coding in C using Allegro.