Skip to content

Commit c9c54a3

Browse files
committed
BSS_Setup: Fix crash on pink sphere teleport
Fixes #302.
1 parent 981b6ac commit c9c54a3

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

SonicMania/Objects/BSS/BSS_Setup.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -849,26 +849,28 @@ void BSS_Setup_State_StartGlobeTeleport(void)
849849
RSDK.SetSpriteAnimation(player2->aniFrames, 0, &player2->animator, true, 0);
850850

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

855-
for (; (count && dir >= 0) && !foundValidPlayerPos; --count) {
856-
for (int32 y = 0; y < BSS_PLAYFIELD_H; ++y) {
857-
for (int32 x = 0; x < BSS_PLAYFIELD_W; ++x) {
858-
uint16 tile = BSS_Setup->playField[y + (BSS_PLAYFIELD_H * x)];
859-
if ((tile & 0x7F) == BSS_SPHERE_PINK && (x != self->playerPos.x || y != self->playerPos.y) && --dir < 0) {
860-
self->playerPos.x = x;
861-
self->playerPos.y = y;
862-
863-
x = 0x20;
864-
y = 0x20;
865-
foundValidPlayerPos = true;
854+
if (count > 1) {
855+
int32 dir = RSDK.Rand(0, count - 1);
856+
for (; (count && dir >= 0) && !foundValidPlayerPos; --count) {
857+
for (int32 y = 0; y < BSS_PLAYFIELD_H; ++y) {
858+
for (int32 x = 0; x < BSS_PLAYFIELD_W; ++x) {
859+
uint16 tile = BSS_Setup->playField[y + (BSS_PLAYFIELD_H * x)];
860+
if ((tile & 0x7F) == BSS_SPHERE_PINK && (x != self->playerPos.x || y != self->playerPos.y) && --dir < 0) {
861+
self->playerPos.x = x;
862+
self->playerPos.y = y;
863+
864+
x = 0x20;
865+
y = 0x20;
866+
foundValidPlayerPos = true;
867+
}
866868
}
867869
}
868870
}
869871
}
870872

871-
dir = RSDK.Rand(0, 4);
873+
int32 dir = RSDK.Rand(0, 4);
872874
bool32 foundValidSpawnDir = false;
873875
for (int32 i = 0; i < 4; ++i) {
874876
int32 x = self->playerPos.x;

0 commit comments

Comments
 (0)