Skip to content

Commit

Permalink
Fix joystick in pause menu (fixes #866)
Browse files Browse the repository at this point in the history
Fix nullptr deref in spall emitter
  • Loading branch information
cxong committed Dec 3, 2024
1 parent c65684d commit 57ee139
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
15 changes: 7 additions & 8 deletions src/cdogs/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ POSSIBILITY OF SUCH DAMAGE.

#include "game_events.h"


void EmitterInit(
Emitter *em, const ParticleClass *p, const struct vec2 offset,
const float minSpeed, const float maxSpeed,
const int minDZ, const int maxDZ,
const double minRotation, const double maxRotation,
const float minSpeed, const float maxSpeed, const int minDZ,
const int maxDZ, const double minRotation, const double maxRotation,
const int ticksPerEmit)
{
memset(em, 0, sizeof *em);
Expand Down Expand Up @@ -62,18 +60,19 @@ void EmitterStart(Emitter *em, const AddParticle *data)
e.u.AddParticle.Class = em->p;
}
const float speed = RAND_FLOAT(em->minSpeed, em->maxSpeed);
const struct vec2 baseVel = svec2_rotate(
svec2(0, speed), RAND_FLOAT(0, MPI * 2));
const struct vec2 baseVel =
svec2_rotate(svec2(0, speed), RAND_FLOAT(0, MPI * 2));
e.u.AddParticle.Vel = svec2_add(data->Vel, baseVel);
if (isnan(data->Angle))
{
e.u.AddParticle.Angle = RAND_FLOAT(0, MPI * 2);
}
e.u.AddParticle.DZ = RAND_FLOAT(em->minDZ, em->maxDZ);
e.u.AddParticle.Spin = RAND_DOUBLE(em->minRotation, em->maxRotation);
if (strlen(e.u.AddParticle.Text) == 0 && em->p->Type == PARTICLE_TEXT)
if (strlen(e.u.AddParticle.Text) == 0 &&
e.u.AddParticle.Class->Type == PARTICLE_TEXT)
{
strcpy(e.u.AddParticle.Text, em->p->u.Text.Value);
strcpy(e.u.AddParticle.Text, e.u.AddParticle.Class->u.Text.Value);
}
GameEventsEnqueue(&gGameEvents, e);
}
Expand Down
28 changes: 18 additions & 10 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,7 @@ static void RunGameInput(GameLoopData *data)
// or the last frame
data->SkipNextFrame = data->SuperhotMode && !lastCmdAll;

// Don't show map if pause menu is shown
if (PauseMenuIsShown(&rData->pm))
{
rData->isMap = false;
// Clear all user inputs if we're using the pause menu
memset(rData->cmds, 0, sizeof rData->cmds);
memset(rData->lastCmds, 0, sizeof rData->lastCmds);
KeyLockKeys(&gEventHandlers.keyboard);
JoyLock(&gEventHandlers.joysticks);
}
const bool wasPaused = PauseMenuIsShown(&rData->pm);

// Update and check if we want to quit
if (PauseMenuUpdate(&rData->pm, rData->cmds, rData->lastCmds))
Expand All @@ -385,6 +376,23 @@ static void RunGameInput(GameLoopData *data)
&gSoundDevice,
StrSound(rData->isMap ? "map_open" : "map_close"));
}
if (wasPaused)
{
// Clear all user inputs if we're using the pause menu
memset(rData->cmds, 0, sizeof rData->cmds);
memset(rData->lastCmds, 0, sizeof rData->lastCmds);
KeyLockKeys(&gEventHandlers.keyboard);
JoyLock(&gEventHandlers.joysticks);
}
}

if (!wasPaused && PauseMenuIsShown(&rData->pm))
{
// Don't show map if pause menu is shown
rData->isMap = false;
// Clear all user inputs if we're using the pause menu
memset(rData->cmds, 0, sizeof rData->cmds);
memset(rData->lastCmds, 0, sizeof rData->lastCmds);
}

CameraInput(&rData->Camera, rData->cmds[0], rData->lastCmds[0]);
Expand Down

0 comments on commit 57ee139

Please sign in to comment.