Skip to content

Commit d9cf9e8

Browse files
committed
fix(map): 범위 밖 시점의 가시성 버퍼 초기화
1 parent d8301a2 commit d9cf9e8

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎tcod/map.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def compute_fov(
246246
RuntimeWarning,
247247
stacklevel=2,
248248
)
249-
map_buffer: NDArray[np.bool_] = np.empty(
249+
map_buffer: NDArray[np.bool_] = np.zeros(
250250
transparency.shape,
251251
dtype=[("transparent", bool), ("walkable", bool), ("fov", bool)],
252252
)

‎tests/test_tcod.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def test_tcod_bsp() -> None:
6060
str(bsp)
6161

6262

63+
@pytest.mark.parametrize("pov", [(-1, 0), (0, -1), (3, 0), (0, 5)])
64+
def test_compute_fov_out_of_bounds(pov: tuple[int, int], monkeypatch: pytest.MonkeyPatch) -> None:
65+
transparency = np.ones((3, 5), dtype=bool)
66+
# Model an uninitialized allocation containing stale visible cells.
67+
monkeypatch.setattr(np, "empty", np.ones)
68+
with pytest.warns(RuntimeWarning, match="outside the array"):
69+
visible = tcod.map.compute_fov(transparency, pov)
70+
assert visible.shape == transparency.shape
71+
assert not visible.any()
72+
73+
6374
@pytest.mark.filterwarnings("ignore:Use map.+ to check for this")
6475
@pytest.mark.filterwarnings("ignore:This class may perform poorly")
6576
def test_tcod_map_set_bits() -> None:

0 commit comments

Comments
 (0)