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

Division by zero crash when window is too small #398

Closed
ieeemma opened this issue Jun 22, 2022 · 2 comments
Closed

Division by zero crash when window is too small #398

ieeemma opened this issue Jun 22, 2022 · 2 comments

Comments

@ieeemma
Copy link

ieeemma commented Jun 22, 2022

When the window becomes smaller than the inited screen size, pyxel fails with

pyo3_runtime.PanicException: attempt to divide by zero

This happens due to screen_scale:

let (window_width, window_height) = self.sdl_canvas.window().size();
let screen_scale = min(
window_width / self.screen_width,
window_height / self.screen_height,
);

Here, screen_scale can be 0 when there is not enough window space vertically or horizontally.

This then causes the division by zero here:

mouse_x = (mouse_x - window_x - screen_x as i32) / screen_scale as i32;
mouse_y = (mouse_y - window_y - screen_y as i32) / screen_scale as i32;

If its relevant, I'm on Linux, though I doubt this is platform specific.

Ideally when there isnt enough space, the game view inside the window would shrink to fit the window size.

@kitao
Copy link
Owner

kitao commented Jun 24, 2022

Thank you for the report.

I expected this issue was prevented by this code:

        sdl_canvas
            .window_mut()
            .set_minimum_size(width, height)
            .unwrap();    

So does it mean there's some environment that ignores minimum size setting?
I continue checking.

@kitao
Copy link
Owner

kitao commented Sep 14, 2022

In the latest Pyxel, I couldn't reproduce this error on Ubuntu. So let me close.

@kitao kitao closed this as completed Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants