Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actor: Free old shells and bazooka remainings #3

Merged
merged 3 commits into from
Sep 19, 2015

Conversation

sriemer
Copy link
Contributor

@sriemer sriemer commented Sep 19, 2015

make: Build debugging symbols

It is very hard to debug issues like segfaults without debugging
symbols and also creating a debug package is not possible this way.
So add the gcc '-g' option to build them.

actor: Fix a segfault in movebullet() ricochet handling

In the ricochet handling in movebullet() sptr is the return value
of spawnactor(). It is dereferenced directly but might be NULL.
The check for NULL is missing and this causes a segfault when
reaching MAX_ACTOR (2048) by shooting a lot of bullets with the
Uzi with unlimited ammo. So return if spawnactor() returns NULL.

actor: Free old shells and bazooka remainings

All actors are stored in an array in static memory. MAX_ACTOR is at
2048. Shells and bazooka remainings are also actors and remain for
the time of the current game. If shooting around two minutes
continuously with the Uzi with unlimited ammo, MAX_ACTOR can be
reached. This makes all weapons ineffective as no more actors can
be spawned.

So free the 200 oldest shells and bazooka remainings if the actor
array is completely filled. Iterate the actors and shift left all
subsequent actors by one if a shell or bazooka remaining is found.
This might segfault if actors are still accessed. So only do that
if further shells or bazooka remainings have to be spawned as these
aren't accessed afterwards. Reserve the last 100 actors for
temporary actors.

Fixes: GitHub issue #2

It is very hard to debug issues like segfaults without debugging
symbols and also creating a debug package is not possible this way.
So add the gcc '-g' option to build them.
In the ricochet handling in movebullet() sptr is the return value
of spawnactor(). It is dereferenced directly but might be NULL.
The check for NULL is missing and this causes a segfault when
reaching MAX_ACTOR (2048) by shooting a lot of bullets with the
Uzi with unlimited ammo. So return if spawnactor() returns NULL.
All actors are stored in an array in static memory. MAX_ACTOR is at
2048. Shells and bazooka remainings are also actors and remain for
the time of the current game. If shooting around two minutes
continuously with the Uzi with unlimited ammo, MAX_ACTOR can be
reached. This makes all weapons ineffective as no more actors can
be spawned.

So free the 200 oldest shells and bazooka remainings if the actor
array is completely filled. Iterate the actors and shift left all
subsequent actors by one if a shell or bazooka remaining is found.
This might segfault if actors are still accessed. So only do that
if further shells or bazooka remainings have to be spawned as these
aren't accessed afterwards. Reserve the last 100 actors for
temporary actors.

Fixes: GitHub issue neuromancer#2
neuromancer added a commit that referenced this pull request Sep 19, 2015
actor: Free old shells and bazooka remainings
@neuromancer neuromancer merged commit 97973f5 into neuromancer:master Sep 19, 2015
@neuromancer
Copy link
Owner

I will accept this pull request, but review the code next week, since i have a deadline on Monday. Thanks for your collaboration. I'm glad you enjoyed the game!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants