mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
Prevent divide by zero
This commit is contained in:
parent
764a4319a0
commit
49a9f189e9
@ -386,13 +386,20 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y,
|
||||
int16_t *res_screen_y)
|
||||
{
|
||||
int scaled_screen_x, scaled_screen_y, scaled_x, scaled_y;
|
||||
int norm_full_vp_width, norm_full_vp_height;
|
||||
struct video_viewport vp = {0};
|
||||
|
||||
if (!video_driver_get_viewport_info(&vp))
|
||||
return false;
|
||||
|
||||
scaled_screen_x = (2 * mouse_x * 0x7fff) / (int)vp.full_width - 0x7fff;
|
||||
scaled_screen_y = (2 * mouse_y * 0x7fff) / (int)vp.full_height - 0x7fff;
|
||||
norm_full_vp_width = (int)vp.full_width;
|
||||
norm_full_vp_height = (int)vp.full_height;
|
||||
|
||||
if (norm_full_vp_width <= 0 || norm_full_vp_height <= 0)
|
||||
return false;
|
||||
|
||||
scaled_screen_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
|
||||
scaled_screen_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
|
||||
if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
|
||||
scaled_screen_x = -0x8000; /* OOB */
|
||||
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
|
||||
@ -401,8 +408,8 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y,
|
||||
mouse_x -= vp.x;
|
||||
mouse_y -= vp.y;
|
||||
|
||||
scaled_x = (2 * mouse_x * 0x7fff) / (int)vp.width - 0x7fff;
|
||||
scaled_y = (2 * mouse_y * 0x7fff) / (int)vp.height - 0x7fff;
|
||||
scaled_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
|
||||
scaled_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
|
||||
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
|
||||
scaled_x = -0x8000; /* OOB */
|
||||
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
|
||||
|
Loading…
Reference in New Issue
Block a user