Fix #117526: Crash when Changing Color Palette in Edit Mode
By default, Color Palettes are only drawn in the UI in the context of
**painting**.
UI button code then tries to update an appropriate brush from edits to
the palette.
So a valid `Paint` and `Brush` were assumed. This is not a problem for
objectmode (because `BKE_paint_get_active_from_context` then defaults to
`ImagePaintSettings`'s `Paint`), but other modes dont guarantee this
(editmode only returns a valid `Paint` when uv sculpting).
In the report, a palette was created and displayed via python, making
changes in editmode would then crash.
Solve by checking we have a valid Paint in corresponding UI code to
begin with.
Similar to 9e82e48937 .
Pull Request: https://projects.blender.org/blender/blender/pulls/117544
This commit is contained in:
committed by
Philipp Oeser
parent
adf67f8a49
commit
a324a19f1b
@@ -6396,41 +6396,43 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
|
||||
if ((event->modifier & KM_CTRL) == 0) {
|
||||
float color[3];
|
||||
Paint *paint = BKE_paint_get_active_from_context(C);
|
||||
Brush *brush = BKE_paint_brush(paint);
|
||||
if (paint != nullptr) {
|
||||
Brush *brush = BKE_paint_brush(paint);
|
||||
|
||||
if (brush->flag & BRUSH_USE_GRADIENT) {
|
||||
float *target = &brush->gradient->data[brush->gradient->cur].r;
|
||||
if (brush->flag & BRUSH_USE_GRADIENT) {
|
||||
float *target = &brush->gradient->data[brush->gradient->cur].r;
|
||||
|
||||
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
|
||||
IMB_colormanagement_srgb_to_scene_linear_v3(target, target);
|
||||
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
|
||||
IMB_colormanagement_srgb_to_scene_linear_v3(target, target);
|
||||
}
|
||||
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
|
||||
}
|
||||
}
|
||||
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
bool updated = false;
|
||||
else {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
bool updated = false;
|
||||
|
||||
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
|
||||
BKE_brush_color_set(scene, brush, color);
|
||||
updated = true;
|
||||
}
|
||||
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
|
||||
IMB_colormanagement_scene_linear_to_srgb_v3(color, color);
|
||||
BKE_brush_color_set(scene, brush, color);
|
||||
updated = true;
|
||||
}
|
||||
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
|
||||
BKE_brush_color_set(scene, brush, color);
|
||||
updated = true;
|
||||
}
|
||||
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
|
||||
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
|
||||
IMB_colormanagement_scene_linear_to_srgb_v3(color, color);
|
||||
BKE_brush_color_set(scene, brush, color);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
PropertyRNA *brush_color_prop;
|
||||
if (updated) {
|
||||
PropertyRNA *brush_color_prop;
|
||||
|
||||
PointerRNA brush_ptr = RNA_id_pointer_create(&brush->id);
|
||||
brush_color_prop = RNA_struct_find_property(&brush_ptr, "color");
|
||||
RNA_property_update(C, &brush_ptr, brush_color_prop);
|
||||
PointerRNA brush_ptr = RNA_id_pointer_create(&brush->id);
|
||||
brush_color_prop = RNA_struct_find_property(&brush_ptr, "color");
|
||||
RNA_property_update(C, &brush_ptr, brush_color_prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user