summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-11-13 10:53:52 +1300
committerBen Bridle <ben@derelict.engineering>2024-11-13 10:54:26 +1300
commit5ca376b56c3a495c9772e546995485159da2e664 (patch)
treea044529fe19e9452a5ae4eccf851734adf447173
parentf40681a72956b36fd5b3dfa596c497935159a372 (diff)
downloadbedrock-pc-5ca376b56c3a495c9772e546995485159da2e664.zip
Fix line drawing issue
An overflow error was causing the line drawing method to loop forever any time a line of length 0x4000 (16384) or longer was drawn. The issue was occurring because both e1 and dx (or dy) would have a value of at least 0x4000, and so on lines 291/292 the sum would exceed 0x8000, the maximum value of an i16. The value would then wrap and break the assumptions of the line drawing algorithm, causing it to loop forever. This was fixed by increasing the size of the affected types.
-rw-r--r--src/devices/screen_device.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/devices/screen_device.rs b/src/devices/screen_device.rs
index 73cfcae..b4eae22 100644
--- a/src/devices/screen_device.rs
+++ b/src/devices/screen_device.rs
@@ -270,11 +270,11 @@ impl ScreenDevice {
let x_end: i16 = self.vector.x as i16;
let y_end: i16 = self.vector.y as i16;
- let dx: i16 = (x_end - x).abs();
- let dy: i16 = -(y_end - y).abs();
+ let dx: i32 = ((x_end as i32) - (x as i32)).abs();
+ let dy: i32 = -((y_end as i32) - (y as i32)).abs();
let sx: i16 = if x < x_end { 1 } else { -1 };
let sy: i16 = if y < y_end { 1 } else { -1 };
- let mut e1: i16 = dx + dy;
+ let mut e1: i32 = dx + dy;
if draw & 0x10 != 0 {
// Draw 1-bit textured line.