Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-09-01 07:40:07 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-09-01 08:00:48 +0300
commita241948ad96be3a9cdf04a0ee53605d3ff4dd82b (patch)
tree8f8cce66ef3dfa19154f5497dc6c44f383b9137d /source/blender/blenkernel/intern/gpencil.c
parentd9d0a386cb02eec14fc8d167e9235fdd18a02c18 (diff)
Fix errors ensuring grease pencil palette
- Direct assignment caused ID user counts to be invalid. - The first palette would always be used, even when the named palette searched for was found. Also pass 'const' string to `hex_to_rgb`, avoid casting to 'non-const'.
Diffstat (limited to 'source/blender/blenkernel/intern/gpencil.c')
-rw-r--r--source/blender/blenkernel/intern/gpencil.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 10b6328ead4..1e37ae3892b 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2110,7 +2110,6 @@ int BKE_gpencil_object_material_index_get(Object *ob, Material *ma)
*/
void BKE_gpencil_palette_ensure(Main *bmain, Scene *scene)
{
- const int totcol = 120;
const char *hexcol[] = {
"FFFFFF", "F2F2F2", "E6E6E6", "D9D9D9", "CCCCCC", "BFBFBF", "B2B2B2", "A6A6A6", "999999",
"8C8C8C", "808080", "737373", "666666", "595959", "4C4C4C", "404040", "333333", "262626",
@@ -2128,33 +2127,34 @@ void BKE_gpencil_palette_ensure(Main *bmain, Scene *scene)
"0000FF", "3F007F", "00007F"};
ToolSettings *ts = scene->toolsettings;
- GpPaint *gp_paint = ts->gp_paint;
- Paint *paint = &gp_paint->paint;
-
- if (paint->palette != NULL) {
+ if (ts->gp_paint->paint.palette != NULL) {
return;
}
- paint->palette = BLI_findstring(&bmain->palettes, "Palette", offsetof(ID, name) + 2);
- /* Try with first palette. */
- if (bmain->palettes.first != NULL) {
- paint->palette = bmain->palettes.first;
- ts->gp_vertexpaint->paint.palette = paint->palette;
- return;
+ /* Try to find the default palette. */
+ const char *palette_id = "Palette";
+ struct Palette *palette = BLI_findstring(&bmain->palettes, palette_id, offsetof(ID, name) + 2);
+
+ if (palette == NULL) {
+ /* Fall back to the first palette. */
+ palette = bmain->palettes.first;
}
- if (paint->palette == NULL) {
- paint->palette = BKE_palette_add(bmain, "Palette");
- ts->gp_vertexpaint->paint.palette = paint->palette;
+ if (palette == NULL) {
+ /* Fall back to creating a palette. */
+ palette = BKE_palette_add(bmain, palette_id);
+ id_us_min(&palette->id);
/* Create Colors. */
- for (int i = 0; i < totcol; i++) {
- PaletteColor *palcol = BKE_palette_color_add(paint->palette);
- if (palcol) {
- hex_to_rgb((char *)hexcol[i], palcol->rgb, palcol->rgb + 1, palcol->rgb + 2);
- }
+ for (int i = 0; i < ARRAY_SIZE(hexcol); i++) {
+ PaletteColor *palcol = BKE_palette_color_add(palette);
+ hex_to_rgb(hexcol[i], palcol->rgb, palcol->rgb + 1, palcol->rgb + 2);
}
}
+
+ BLI_assert(palette != NULL);
+ BKE_paint_palette_set(&ts->gp_paint->paint, palette);
+ BKE_paint_palette_set(&ts->gp_vertexpaint->paint, palette);
}
/**