Fix #130998: Crash changing Color Palette in Object/Edit/Pose modes

Caused by 7b0ea0f1b4

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.

In the report though, a palette was created and displayed via python,
making changes in Object/Edit/Pose would then crash.

So a valid `Paint` and `Brush` were assumed. `Paint` was already checked
for in a324a19f1b, but since 7b0ea0f1b4, `Paint`(if we actually have
it, e.g.from `ImagePaintSettings` [see a324a19f1b]) only has its
`brush` set once we enter texturepaint once.

Solved by checking we have a valid Brush in corresponding UI code to
begin with.

Pull Request: https://projects.blender.org/blender/blender/pulls/131031
This commit is contained in:
Philipp Oeser
2024-11-27 15:41:26 +01:00
committed by Philipp Oeser
parent 953c4f1599
commit 5aa95941d1

View File

@@ -6503,7 +6503,10 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
if (paint != nullptr) {
Brush *brush = BKE_paint_brush(paint);
if (brush->flag & BRUSH_USE_GRADIENT) {
if (brush == nullptr) {
/* Pass. */
}
else 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) {