Prevent int overflow when projecting target reticle on screen; close #48

This commit is contained in:
Dominic Szablewski 2023-08-26 17:49:42 +02:00
parent 41399234f6
commit da4d3b5c0c

View file

@ -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