From d1766b252dd82780c10ff0957d925a1d45af75b5 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 6 Jun 2020 15:20:48 +1000 Subject: [PATCH] Don't throw an exception on 0 width/height canvas, addresses #669 --- src/Window.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Window.c b/src/Window.c index 323f086b2..07fdc4686 100644 --- a/src/Window.c +++ b/src/Window.c @@ -3009,8 +3009,14 @@ static void RescaleXY(int srcX, int srcY, int* dstX, int* dstY) { double css_width, css_height; emscripten_get_element_css_size("#canvas", &css_width, &css_height); - *dstX = (int)(srcX * WindowInfo.Width / css_width); - *dstY = (int)(srcY * WindowInfo.Height / css_height); + if (css_width && css_height) { + *dstX = (int)(srcX * WindowInfo.Width / css_width ); + *dstY = (int)(srcY * WindowInfo.Height / css_height); + } else { + /* If css width or height is 0, something is bogus */ + /* It's still better to avoid divsision by 0 anyways */ + *dstX = srcX; *dstY = srcY; + } } static EM_BOOL OnMouseMove(int type, const EmscriptenMouseEvent* ev, void* data) {