Don't access preferences from background thread and check current_editor existence

Related to #2874 and ac31ee35c0
This commit is contained in:
David Capello 2021-09-01 12:11:02 -03:00
parent 6341fcee23
commit 013792a215

View File

@ -40,6 +40,22 @@ using namespace gfx;
namespace {
gfx::Color gridColor1()
{
if (ui::is_ui_thread() && current_editor)
return color_utils::color_for_ui(current_editor->docPref().bg.color1());
else
return gfx::rgba(128, 128, 128);
}
gfx::Color gridColor2()
{
if (ui::is_ui_thread() && current_editor)
return color_utils::color_for_ui(current_editor->docPref().bg.color2());
else
return gfx::rgba(192, 192, 192);
}
void draw_checked_grid(ui::Graphics* g,
const gfx::Rect& rc,
const gfx::Size& tile,
@ -78,9 +94,7 @@ void draw_checked_grid(ui::Graphics* g,
const gfx::Rect& rc,
const gfx::Size& tile)
{
draw_checked_grid(g, rc, tile,
color_utils::color_for_ui(current_editor->docPref().bg.color1()),
color_utils::color_for_ui(current_editor->docPref().bg.color2()));
draw_checked_grid(g, rc, tile, gridColor1(), gridColor2());
}
void draw_checked_grid(ui::Graphics* g,
@ -88,9 +102,7 @@ void draw_checked_grid(ui::Graphics* g,
const gfx::Size& tile,
DocumentPreferences& docPref)
{
draw_checked_grid(g, rc, tile,
color_utils::color_for_ui(docPref.bg.color1()),
color_utils::color_for_ui(docPref.bg.color2()));
draw_checked_grid(g, rc, tile, gridColor1(), gridColor2());
}
void draw_color(ui::Graphics* g,
@ -192,8 +204,8 @@ void draw_alpha_slider(ui::Graphics* g,
for (int x=0; x<rc.w; ++x) {
const int a = (255 * x / xmax);
const doc::color_t c1 = doc::rgba_blender_normal(color_utils::color_for_ui(current_editor->docPref().bg.color1()), c, a);
const doc::color_t c2 = doc::rgba_blender_normal(color_utils::color_for_ui(current_editor->docPref().bg.color2()), c, a);
const doc::color_t c1 = doc::rgba_blender_normal(gridColor1(), c, a);
const doc::color_t c2 = doc::rgba_blender_normal(gridColor2(), c, a);
const int mid = rc.h/2;
const int odd = (x / rc.h) & 1;
g->drawVLine(
@ -220,8 +232,8 @@ void draw_alpha_slider(os::Surface* s,
os::Paint paint;
for (int x=0; x<rc.w; ++x) {
const int a = (255 * x / xmax);
const doc::color_t c1 = doc::rgba_blender_normal(color_utils::color_for_ui(current_editor->docPref().bg.color1()), c, a);
const doc::color_t c2 = doc::rgba_blender_normal(color_utils::color_for_ui(current_editor->docPref().bg.color2()), c, a);
const doc::color_t c1 = doc::rgba_blender_normal(gridColor1(), c, a);
const doc::color_t c2 = doc::rgba_blender_normal(gridColor2(), c, a);
const int mid = rc.h/2;
const int odd = (x / rc.h) & 1;