From da4d3b5c0c8ac6b7b210c6de9a80e52d4106ebbb Mon Sep 17 00:00:00 2001 From: Dominic Szablewski Date: Sat, 26 Aug 2023 17:49:42 +0200 Subject: [PATCH] Prevent int overflow when projecting target reticle on screen; close #48 --- src/wipeout/hud.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wipeout/hud.c b/src/wipeout/hud.c index d8631ad..98acc8b 100755 --- a/src/wipeout/hud.c +++ b/src/wipeout/hud.c @@ -170,6 +170,15 @@ static void hud_draw_target_icon(vec3_t position) { vec2i_t size = ui_scaled(render_texture_size(target_reticle)); vec3_t projected = render_transform(position); + // Not on screen? + if ( + projected.x < -1 || projected.x > 1 || + projected.y < -1 || projected.y > 1 || + projected.z >= 1 + ) { + return; + } + vec2i_t pos = vec2i( (( projected.x + 1.0) / 2.0) * screen_size.x - size.x / 2, ((-projected.y + 1.0) / 2.0) * screen_size.y - size.y / 2