Skip to content
Snippets Groups Projects
Commit 4ef309b4 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix SF tickets 113 and maybe 111

Fix infinite loop in bitmap_drv_init_mode() if scaling results in
larger than max size.

This uncovered an issue in resize_window() which would cause the
screen to be corrupted due to vstat not agreeing to the actual window.
parent 6b678f68
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4401 failed
...@@ -1827,11 +1827,15 @@ int bitmap_drv_init_mode(int mode, int *width, int *height, int maxwidth, int ma ...@@ -1827,11 +1827,15 @@ int bitmap_drv_init_mode(int mode, int *width, int *height, int maxwidth, int ma
ns = ls; ns = ls;
break; break;
} }
if (w == maxwidth)
break;
if ((maxheight > 0) && (h > maxheight)) { if ((maxheight > 0) && (h > maxheight)) {
mult--; mult--;
ns = ls; ns = ls;
break; break;
} }
if (h == maxheight)
break;
bs = ((int64_t)w * w) + ((int64_t)h * h); bs = ((int64_t)w * w) + ((int64_t)h * h);
ls = ns; ls = ns;
ns = bs; ns = bs;
......
...@@ -642,9 +642,16 @@ static void resize_window() ...@@ -642,9 +642,16 @@ static void resize_window()
{ {
int width = x_cvstat.scrnwidth * x_cvstat.scaling; int width = x_cvstat.scrnwidth * x_cvstat.scaling;
int height = x_cvstat.scrnheight * x_cvstat.scaling; int height = x_cvstat.scrnheight * x_cvstat.scaling;
int max_width, max_height;
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
bitmap_get_scaled_win_size(x_cvstat.scaling, &width, &height, 0, 0); bitmap_get_scaled_win_size(x_cvstat.scaling, &width, &height, 0, 0);
if (x11_get_maxsize(&max_width, &max_height)) {
if (width > max_width || height > max_height) {
x_cvstat.scaling = bitmap_double_mult_inside(max_width, max_height);
bitmap_get_scaled_win_size(x_cvstat.scaling, &width, &height, 0, 0);
}
}
if (width == vstat.winwidth && height == vstat.winheight) { if (width == vstat.winwidth && height == vstat.winheight) {
x_cvstat.scaling = bitmap_double_mult_inside(width, height); x_cvstat.scaling = bitmap_double_mult_inside(width, height);
vstat.scaling = x_cvstat.scaling; vstat.scaling = x_cvstat.scaling;
...@@ -652,12 +659,11 @@ static void resize_window() ...@@ -652,12 +659,11 @@ static void resize_window()
resize_xim(); resize_xim();
return; return;
} }
x_cvstat.winwidth = vstat.winwidth; x_cvstat.winwidth = width;
x_cvstat.winheight = vstat.winheight; x_cvstat.winheight = height;
x_cvstat.scaling = bitmap_double_mult_inside(width, height); x_cvstat.scaling = bitmap_double_mult_inside(width, height);
vstat.scaling = x_cvstat.scaling;
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
x11.XResizeWindow(dpy, win, width, height); x11.XResizeWindow(dpy, win, width, height));
resize_xim(); resize_xim();
return; return;
...@@ -667,6 +673,7 @@ static void init_mode_internal(int mode) ...@@ -667,6 +673,7 @@ static void init_mode_internal(int mode)
{ {
int mw, mh; int mw, mh;
int ow, oh; int ow, oh;
double os;
x11_get_maxsize(&mw, &mh); x11_get_maxsize(&mw, &mh);
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
...@@ -676,10 +683,13 @@ static void init_mode_internal(int mode) ...@@ -676,10 +683,13 @@ static void init_mode_internal(int mode)
} }
ow = vstat.winwidth; ow = vstat.winwidth;
oh = vstat.winheight; oh = vstat.winheight;
os = vstat.scaling;
bitmap_drv_init_mode(mode, NULL, NULL, mw, mh); bitmap_drv_init_mode(mode, NULL, NULL, mw, mh);
x_cvstat = vstat; x_cvstat = vstat;
x_cvstat.scaling = bitmap_double_mult_inside(vstat.winwidth, vstat.winheight);
vstat.winwidth = ow; vstat.winwidth = ow;
vstat.winheight = oh; vstat.winheight = oh;
vstat.scaling = os;
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
resize_window(); resize_window();
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
...@@ -709,7 +719,6 @@ static void check_scaling(void) ...@@ -709,7 +719,6 @@ static void check_scaling(void)
static int init_mode(int mode) static int init_mode(int mode)
{ {
init_mode_internal(mode); init_mode_internal(mode);
resize_window();
bitmap_drv_request_pixels(); bitmap_drv_request_pixels();
sem_post(&mode_set); sem_post(&mode_set);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment