Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Add missing asserts in the FOV map functions
Browse files Browse the repository at this point in the history
We were only checking that the x and y were greater or equal to zero,
but they must also be lower than the map's width and height.

Discovered this when my roguelike crashed because of this (assert within
libtcod itself).
  • Loading branch information
tomassedovic committed Apr 3, 2016
1 parent 9a3b435 commit bdc6d54
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ impl Map {

pub fn set(&mut self, x: i32, y: i32, transparent: bool, walkable: bool) {
assert!(x >= 0 && y >= 0);
let (width, height) = self.size();
assert!(x < width && y < height);
unsafe {
ffi::TCOD_map_set_properties(self.tcod_map, x, y,
transparent as c_bool,
Expand All @@ -47,13 +49,17 @@ impl Map {

pub fn is_in_fov(&self, x: i32, y: i32) -> bool {
assert!(x >= 0 && y >= 0);
let (width, height) = self.size();
assert!(x < width && y < height);
unsafe {
ffi::TCOD_map_is_in_fov(self.tcod_map, x, y) != 0
}
}

pub fn is_walkable(&self, x: i32, y: i32) -> bool {
assert!(x >= 0 && y >= 0);
let (width, height) = self.size();
assert!(x < width && y < height);
unsafe {
ffi::TCOD_map_is_walkable(self.tcod_map, x, y) != 0
}
Expand Down

0 comments on commit bdc6d54

Please sign in to comment.