From f8a334c90f33879de88734d2a68ca14c386418cf Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 27 Feb 2015 23:42:51 +0000 Subject: [PATCH 1/2] Fix memory corruption when saving. --- src/util/sawyercoding.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/sawyercoding.c b/src/util/sawyercoding.c index 3e669ae6d3..1388085d32 100644 --- a/src/util/sawyercoding.c +++ b/src/util/sawyercoding.c @@ -163,10 +163,14 @@ int sawyercoding_write_chunk_buffer(uint8 *dst_file, uint8* buffer, sawyercoding free(encode_buffer); break; case CHUNK_ENCODING_ROTATE: - encode_chunk_rotate(buffer, chunkHeader.length); + encode_buffer = malloc(chunkHeader.length); + memcpy(encode_buffer, buffer, chunkHeader.length); + encode_chunk_rotate(encode_buffer, chunkHeader.length); memcpy(dst_file, &chunkHeader, sizeof(sawyercoding_chunk_header)); dst_file += sizeof(sawyercoding_chunk_header); - memcpy(dst_file, buffer, chunkHeader.length); + memcpy(dst_file, encode_buffer, chunkHeader.length); + + free(encode_buffer); break; } From 2b2ca7c7b3af7cdf46d6302d8ef28ad13b19f9f6 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 28 Feb 2015 00:20:34 +0000 Subject: [PATCH 2/2] Fix zoomed saves incorrectly loading --- src/editor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/editor.c b/src/editor.c index 6b9f0d36a6..5065445e99 100644 --- a/src/editor.c +++ b/src/editor.c @@ -932,18 +932,18 @@ static int editor_read_s6(const char *path) w->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16); w->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16); + int zoom_difference = (RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF) - viewport->zoom; viewport->zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) & 0xFF; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) >> 8; - int cx = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) - viewport->zoom; - if (cx != 0) { - if (cx >= 0) { - viewport->view_width <<= cx; - viewport->view_height <<= cx; + if (zoom_difference != 0) { + if (zoom_difference >= 0) { + viewport->view_width <<= zoom_difference; + viewport->view_height <<= zoom_difference; } else { - cx = -cx; - viewport->view_width >>= cx; - viewport->view_height >>= cx; + zoom_difference = -zoom_difference; + viewport->view_width >>= zoom_difference; + viewport->view_height >>= zoom_difference; } } w->saved_view_x -= viewport->view_width >> 1;