mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
js: Make update_pixel_ratio() more robust
With very small tile sizes, js_canvas_find_font_midpoint() can throw an exception. When it was called from update_pixel_ratio(), this prevented the new MediaQueryList from being created, which meant that the puzzle stopped noticing changes of device pixel ratio. Now update_pixel_ratio() establishes a new MediaQueryList before calling rescale_puzzle(), so the exception can't break it. Catching the exception properly would be even better, of course.
This commit is contained in:
@ -547,9 +547,9 @@ function initPuzzle() {
|
|||||||
var dpr = window.devicePixelRatio;
|
var dpr = window.devicePixelRatio;
|
||||||
if (mql !== null)
|
if (mql !== null)
|
||||||
mql.removeListener(update_pixel_ratio);
|
mql.removeListener(update_pixel_ratio);
|
||||||
rescale_puzzle(nominal_width * dpr, nominal_height * dpr);
|
|
||||||
mql = window.matchMedia(`(resolution: ${dpr}dppx)`);
|
mql = window.matchMedia(`(resolution: ${dpr}dppx)`);
|
||||||
mql.addListener(update_pixel_ratio);
|
mql.addListener(update_pixel_ratio);
|
||||||
|
rescale_puzzle(nominal_width * dpr, nominal_height * dpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module.onRuntimeInitialized = function() {
|
Module.onRuntimeInitialized = function() {
|
||||||
|
Reference in New Issue
Block a user