Skip to content

Commit

Permalink
Moved some functionality into del_hare function to fix "access of fre…
Browse files Browse the repository at this point in the history
…ed memory" error.
  • Loading branch information
theZiz committed May 1, 2017
1 parent 08dafa3 commit 3ac3b0f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 35 deletions.
3 changes: 2 additions & 1 deletion ToDo
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

* Fix bug
* Improve camera
14 changes: 1 addition & 13 deletions bullet.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,19 +802,7 @@ int updateBullets()
hare->high_hops = 3;
}
if (hare->health <= 0)
{
if (hare == player[j]->activeHare ||
hare == player[j]->setActiveHare)
{
player[j]->setActiveHare = hare->next;
player[j]->activeHare = NULL;
if (j == active_player)//Suicid!
next_player();
}
hare = del_hare(hare,&(player[j]->firstHare));
if (player[j]->firstHare == NULL)
alive_count--;
}
hare = del_hare(hare,player[j]);
else
hare = hare->next;
}
Expand Down
10 changes: 4 additions & 6 deletions hase.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,9 @@ int calc(Uint32 steps)
&d);
if (player[active_player]->activeHare->circle_checkpoint_hare[j]->health <= 0)
{
player[active_player]->activeHare->circle_checkpoint_hare[j] = del_hare(player[active_player]->activeHare->circle_checkpoint_hare[j],&(p->firstHare));
if (p->firstHare == NULL)
alive_count--;
del_hare(player[active_player]->activeHare->circle_checkpoint_hare[j],p);
if (alive_count < 2)
result = 2;
}
free(bullet);
once = 1;
Expand Down Expand Up @@ -1804,9 +1804,7 @@ int calc(Uint32 steps)
&d);
if (player[active_player]->activeHare->circle_checkpoint_hare[j]->health <= 0)
{
player[active_player]->activeHare->circle_checkpoint_hare[j] = del_hare(player[active_player]->activeHare->circle_checkpoint_hare[j],&(p->firstHare));
if (p->firstHare == NULL)
alive_count--;
del_hare(player[active_player]->activeHare->circle_checkpoint_hare[j],p);
if (alive_count < 2)
result = 2;
}
Expand Down
12 changes: 1 addition & 11 deletions logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,7 @@ int do_physics()
}
if (((hase_game->options.bytewise.ragnarok_border & 15) == 0) && (hare->x < 0 || hare->y < 0 || hare->x >= spIntToFixed(LEVEL_WIDTH) || hare->y >= spIntToFixed(LEVEL_HEIGHT)))
{
if (hare == player[j]->activeHare ||
hare == player[j]->setActiveHare)
{
player[j]->setActiveHare = hare->next;
player[j]->activeHare = NULL;
if (j == active_player)//Suicid!
next_player();
}
hare = del_hare(hare,&(player[j]->firstHare));
if (player[j]->firstHare == NULL)
alive_count--;
hare = del_hare(hare,player[j]);
if (alive_count < 2)
return 1;
}
Expand Down
19 changes: 15 additions & 4 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,17 +713,28 @@ void hareplosion(pHare hare)
}
}

pHare del_hare(pHare hare,pHare* firstHare)
pHare del_hare(pHare hare,pPlayer p)
{
if (hare == p->activeHare ||
hare == p->setActiveHare)
{
p->setActiveHare = hare->next;
p->activeHare = NULL;
if (p == player[active_player])//Suicid!
next_player();
}
pHare next = NULL;
if (hare->next == hare)
*firstHare = NULL;
{
p->firstHare = NULL;
alive_count--;
}
else
{
hare->before->next = hare->next;
hare->next->before = hare->before;
if (*firstHare == hare)
*firstHare = hare->next;
if (p->firstHare == hare)
p->firstHare = hare->next;
next = hare->next;
}
hareplosion(hare);
Expand Down

0 comments on commit 3ac3b0f

Please sign in to comment.