Fix: Sculpt paint crash after converting active color attribute
Painting after converting active color attribute in sculpt mode causes crash.
Fix is same as 3641b4b884
with some cleanup
Pull Request: https://projects.blender.org/blender/blender/pulls/119780
This commit is contained in:
parent
0709c07d04
commit
b3fe97414a
|
@ -112,6 +112,7 @@ void BKE_id_attributes_active_color_set(struct ID *id, const char *name);
|
|||
void BKE_id_attributes_default_color_set(struct ID *id, const char *name);
|
||||
|
||||
const struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name);
|
||||
bool BKE_color_attribute_supported(const struct Mesh &mesh, const blender::StringRef name);
|
||||
|
||||
std::string BKE_id_attribute_calc_unique_name(const struct ID &id, const blender::StringRef name);
|
||||
|
||||
|
|
|
@ -933,6 +933,22 @@ const CustomDataLayer *BKE_id_attributes_color_find(const ID *id, const char *na
|
|||
const_cast<ID *>(id), name, CD_MASK_COLOR_ALL, ATTR_DOMAIN_MASK_COLOR);
|
||||
}
|
||||
|
||||
bool BKE_color_attribute_supported(const Mesh &mesh, const blender::StringRef name)
|
||||
{
|
||||
std::optional<blender::bke::AttributeMetaData> meta_data = mesh.attributes().lookup_meta_data(
|
||||
name);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const char *BKE_uv_map_vert_select_name_get(const char *uv_map_name, char *buffer)
|
||||
{
|
||||
BLI_assert(strlen(UV_VERTSEL_NAME) == 2);
|
||||
|
|
|
@ -1909,7 +1909,7 @@ void BKE_sculpt_color_layer_create_if_needed(Object *object)
|
|||
using namespace blender::bke;
|
||||
Mesh *orig_me = BKE_object_get_original_mesh(object);
|
||||
|
||||
if (orig_me->attributes().contains(orig_me->active_color_attribute)) {
|
||||
if (BKE_color_attribute_supported(*orig_me, orig_me->active_color_attribute)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -430,15 +430,8 @@ bool ED_mesh_color_ensure(Mesh *mesh, const char *name)
|
|||
{
|
||||
using namespace blender;
|
||||
BLI_assert(mesh->runtime->edit_mesh == nullptr);
|
||||
const bke::AttributeAccessor attributes = mesh->attributes();
|
||||
if (const std::optional<bke::AttributeMetaData> 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;
|
||||
}
|
||||
if (BKE_color_attribute_supported(*mesh, mesh->active_color_attribute)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string unique_name = BKE_id_attribute_calc_unique_name(mesh->id, name);
|
||||
|
|
|
@ -600,24 +600,6 @@ 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<bke::AttributeMetaData> 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);
|
||||
|
@ -630,7 +612,7 @@ bool vertex_paint_mode_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!color_attribute_supported(*mesh, mesh->active_color_attribute)) {
|
||||
if (!BKE_color_attribute_supported(*mesh, mesh->active_color_attribute)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1013,7 +995,7 @@ static bool vpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
|
|||
|
||||
const std::optional<bke::AttributeMetaData> meta_data = *mesh->attributes().lookup_meta_data(
|
||||
mesh->active_color_attribute);
|
||||
if (!color_attribute_supported(meta_data)) {
|
||||
if (!BKE_color_attribute_supported(*mesh, mesh->active_color_attribute)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue