Problem in removing nodes on a list

Asked

Viewed 36 times

0

Good night,

I’m doing a show that’s sort of a "Candy Crush" on SDL. And I needed your help to help me remove the balls from the game, which in this case are the nodes on the list.

The program is going through the game looking for the nodes that have to remove that are marked with 1 on the field defenicoes..

I hope you were more specific this time!!!

Thanks for the help!

Errorr: segmentaion fault (Core dumped)

bolhas_ligadas *remove_bolhas(bolhas_ligadas *lista,int largura,int altura){
  bolhas_ligadas *aux,*aux4;
  int i,j;
  aux=lista;
  for(j=0;j<largura;j++){

    for(i=0;i<altura;i++){

      aux4=aux->next;
      if(aux4->defenicoes.marca==1){

        aux->next=aux4->next;  
        free(aux4);   
      }

      aux=aux->next;

    }
  } 
  return lista;
}
  • How the links were established next among the various bolhas_ligadas ? Also put this part in the question

  • Have you tried running this with GDB to know exactly where the segmentaion fault (Core dumped)? What I can see is that you can’t compare aux is valid during looping, probably you exhaust the list elements at some point, and when looping back it tries to access area of improper memories.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.