From 3641b4b884ab4b117cab3c800d16b2ac5263a7a1 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 19 Mar 2024 19:49:00 +0100 Subject: [PATCH 1/2] Fix #119586: Vertex paint mode crash after converting color attribute Converting a color attribute to a non-color domain or type causes vertex paint mode to try to change the attribute even though it's unsupported. That leads to a crash here and unpredictable behavior elsewhere. This PR modifies some poll functions to check for the proper domain and data type before continuing. Even if converting an attribute properly updates the active color attribute, we can still run into situations where the active name references an attribute with incorrect metadata. Pull Request: https://projects.blender.org/blender/blender/pulls/119657 --- source/blender/editors/mesh/mesh_data.cc | 11 +++++++-- .../editors/sculpt_paint/paint_vertex.cc | 23 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index 38741dc4493..f088aaaab11 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -437,8 +437,15 @@ bool ED_mesh_color_ensure(Mesh *mesh, const char *name) { using namespace blender; BLI_assert(mesh->edit_mesh == nullptr); - if (mesh->attributes().contains(mesh->active_color_attribute)) { - return true; + const bke::AttributeAccessor attributes = mesh->attributes(); + if (const std::optional meta_data = attributes.lookup_meta_data( + mesh->active_color_attribute)) + { + if ((ATTR_DOMAIN_AS_MASK(meta_data->domain) & ATTR_DOMAIN_MASK_COLOR) && + (CD_TYPE_AS_MASK(meta_data->data_type) & CD_MASK_COLOR_ALL)) + { + return true; + } } const std::string unique_name = BKE_id_attribute_calc_unique_name(mesh->id, name); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index ebccb4b6f21..a37c97775e7 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -597,6 +597,24 @@ void smooth_brush_toggle_on(const bContext *C, Paint *paint, StrokeCache *cache) /** \} */ } // namespace blender::ed::sculpt_paint::vwpaint +static bool color_attribute_supported(const std::optional meta_data) +{ + if (!meta_data) { + return false; + } + if (!(ATTR_DOMAIN_AS_MASK(meta_data->domain) & ATTR_DOMAIN_MASK_COLOR) || + !(CD_TYPE_AS_MASK(meta_data->data_type) & CD_MASK_COLOR_ALL)) + { + return false; + } + return true; +} + +static bool color_attribute_supported(const Mesh &mesh, const StringRef name) +{ + return color_attribute_supported(mesh.attributes().lookup_meta_data(name)); +} + bool vertex_paint_mode_poll(bContext *C) { const Object *ob = CTX_data_active_object(C); @@ -609,7 +627,7 @@ bool vertex_paint_mode_poll(bContext *C) return false; } - if (!mesh->attributes().contains(mesh->active_color_attribute)) { + if (!color_attribute_supported(*mesh, mesh->active_color_attribute)) { return false; } @@ -991,8 +1009,7 @@ static bool vpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo const std::optional meta_data = *mesh->attributes().lookup_meta_data( mesh->active_color_attribute); - - if (!meta_data) { + if (!color_attribute_supported(meta_data)) { return false; } From 3c25b079cef557e6889b62985ee3b3be9fcfc1b4 Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Wed, 20 Mar 2024 08:33:29 +0100 Subject: [PATCH 2/2] Fix #109739: Resolve greyed out UI on MacOS UI would sometimes disappear with the Metal backend. This occured in situations where there was only a single GPUContext within a single GHOST window, meaning the activation routine for the context was never run. Context activation is required to ensure the backbuffer was up to date upon resize. Otherwise, re-sizing the window would cause the screen to turn grey as the new drawables would not be rendered to. Authored by Apple: Michael Parkin-White Co-authored-by: Michael Parkin-White Pull Request: https://projects.blender.org/blender/blender/pulls/119299 --- source/blender/windowmanager/intern/wm_draw.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/windowmanager/intern/wm_draw.cc b/source/blender/windowmanager/intern/wm_draw.cc index a64dd81ef03..c72221c901b 100644 --- a/source/blender/windowmanager/intern/wm_draw.cc +++ b/source/blender/windowmanager/intern/wm_draw.cc @@ -1544,6 +1544,13 @@ void wm_draw_update(bContext *C) BKE_image_free_unused_gpu_textures(); +#ifdef WITH_METAL_BACKEND + /* Reset drawable to ensure GPU context activation happens at least once per frame if only a + * single context exists. This is required to ensure the default framebuffer is updated + * to be the latest backbuffer. */ + wm_window_clear_drawable(wm); +#endif + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { #ifdef WIN32 GHOST_TWindowState state = GHOST_GetWindowState(