Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash from negative array index for visibility_cache #75521

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/pixel_minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ void pixel_minimap::render_critters( const tripoint &center )
mixture = lerp_clamped( 0, 100, std::max( s, 0.0f ) );
}

const level_cache &access_cache = get_map().access_cache( center.z );
const map &m = get_map();
const level_cache &access_cache = m.access_cache( center.z );

const point start( center.x - total_tiles_count.x / 2, center.y - total_tiles_count.y / 2 );
const point beacon_size = {
Expand All @@ -518,6 +519,10 @@ void pixel_minimap::render_critters( const tripoint &center )
for( int y = 0; y < total_tiles_count.y; y++ ) {
for( int x = 0; x < total_tiles_count.x; x++ ) {
const tripoint p = start + tripoint( x, y, center.z );
if( !m.inbounds( p ) ) {
// p might be out-of-bounds when peeking at submap boundary. Example: center=(64,59,-5), start=(4,-1) -> p=(4,-1,-5)
continue;
}
const lit_level lighting = access_cache.visibility_cache[p.x][p.y];

if( lighting == lit_level::DARK || lighting == lit_level::BLANK ) {
Expand Down
Loading