From 17abada57e1f06222582f83846b8f9304103fd59 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 3 Jun 2015 19:00:16 +0100 Subject: [PATCH] Fix invalid locations breaking viewports Fixes #1183. Note this isn't the same fix that rct2 uses. But I feel it solves the main issue --- src/interface/viewport.c | 9 +++++++++ src/world/sprite.c | 4 ++-- src/world/sprite.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 29d450731e..8c8522754b 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -147,6 +147,15 @@ void center_2d_coordinates(int x, int y, int z, int* out_x, int* out_y, rct_view break; } + // If the start location was invalid + // propagate the invalid location to the output. + // This fixes a bug that caused the game to enter an infinite loop. + if (start_x == (sint16)0x8000){ + *out_x = (sint16)0x8000; + *out_y = 0; + return; + } + *out_x = x - viewport->view_width / 2; *out_y = y - viewport->view_height / 2; } diff --git a/src/world/sprite.c b/src/world/sprite.c index 1ad644cae1..067b62c13a 100644 --- a/src/world/sprite.c +++ b/src/world/sprite.c @@ -806,7 +806,7 @@ void sprite_misc_update_all() * cx: y * dx: z */ -void sprite_move(int x, int y, int z, rct_sprite* sprite){ +void sprite_move(sint16 x, sint16 y, sint16 z, rct_sprite* sprite){ int new_position = x; if (x == (sint16)0x8000)new_position = 0x10000; else{ @@ -842,7 +842,7 @@ void sprite_move(int x, int y, int z, rct_sprite* sprite){ sprite->unknown.z = z; return; } - int new_x = x, new_y = y, start_x = x; + sint16 new_x = x, new_y = y, start_x = x; switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)){ case 0: new_x = new_y - new_x; diff --git a/src/world/sprite.h b/src/world/sprite.h index 190c0efcb0..52d66f2d24 100644 --- a/src/world/sprite.h +++ b/src/world/sprite.h @@ -245,7 +245,7 @@ void reset_sprite_list(); void reset_0x69EBE4(); void move_sprite_to_list(rct_sprite *sprite, uint8 cl); void sprite_misc_update_all(); -void sprite_move(int x, int y, int z, rct_sprite* sprite); +void sprite_move(sint16 x, sint16 y, sint16 z, rct_sprite* sprite); void invalidate_sprite(rct_sprite *sprite); void sub_6EC60B(rct_sprite* sprite); void sprite_remove(rct_sprite *sprite);