Skip to content

Commit

Permalink
BSS_Setup: Fix crash on pink sphere teleport
Browse files Browse the repository at this point in the history
Fixes #302.
  • Loading branch information
Mefiresu committed Dec 17, 2024
1 parent 981b6ac commit c9c54a3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions SonicMania/Objects/BSS/BSS_Setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,26 +849,28 @@ void BSS_Setup_State_StartGlobeTeleport(void)
RSDK.SetSpriteAnimation(player2->aniFrames, 0, &player2->animator, true, 0);

int32 count = BSS_Setup->pinkSphereCount;
int32 dir = RSDK.Rand(0, count - 1);
bool32 foundValidPlayerPos = false;

for (; (count && dir >= 0) && !foundValidPlayerPos; --count) {
for (int32 y = 0; y < BSS_PLAYFIELD_H; ++y) {
for (int32 x = 0; x < BSS_PLAYFIELD_W; ++x) {
uint16 tile = BSS_Setup->playField[y + (BSS_PLAYFIELD_H * x)];
if ((tile & 0x7F) == BSS_SPHERE_PINK && (x != self->playerPos.x || y != self->playerPos.y) && --dir < 0) {
self->playerPos.x = x;
self->playerPos.y = y;

x = 0x20;
y = 0x20;
foundValidPlayerPos = true;
if (count > 1) {
int32 dir = RSDK.Rand(0, count - 1);
for (; (count && dir >= 0) && !foundValidPlayerPos; --count) {
for (int32 y = 0; y < BSS_PLAYFIELD_H; ++y) {
for (int32 x = 0; x < BSS_PLAYFIELD_W; ++x) {
uint16 tile = BSS_Setup->playField[y + (BSS_PLAYFIELD_H * x)];
if ((tile & 0x7F) == BSS_SPHERE_PINK && (x != self->playerPos.x || y != self->playerPos.y) && --dir < 0) {
self->playerPos.x = x;
self->playerPos.y = y;

x = 0x20;
y = 0x20;
foundValidPlayerPos = true;
}
}
}
}
}

dir = RSDK.Rand(0, 4);
int32 dir = RSDK.Rand(0, 4);
bool32 foundValidSpawnDir = false;
for (int32 i = 0; i < 4; ++i) {
int32 x = self->playerPos.x;
Expand Down

0 comments on commit c9c54a3

Please sign in to comment.