Fix #125230: Issues when loading file with pinning gpencil brush material
Brushes and changes done to them are preserved now when loading different files (until Blender closes). Unpin and clear the material assigned to the brush when loading a different file, since this material is local to the previous file. Pull Request: https://projects.blender.org/blender/blender/pulls/128080
This commit is contained in:
committed by
Julian Eisel
parent
c182dadf9f
commit
d9748470fa
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_brush_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
@@ -510,6 +512,27 @@ static void reuse_editable_asset_bmain_data_for_blendfile(ReuseOldBMainData *reu
|
||||
FOREACH_MAIN_LISTBASE_ID_END;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grease pencil brushes may have a material pinned that is from the current file. Moving local
|
||||
* scene data to a different #Main is tricky, so in that case, unpin the material.
|
||||
*/
|
||||
static void unpin_file_local_grease_pencil_brush_materials(const ReuseOldBMainData *reuse_data)
|
||||
{
|
||||
ID *old_id_iter;
|
||||
FOREACH_MAIN_LISTBASE_ID_BEGIN (&reuse_data->old_bmain->brushes, old_id_iter) {
|
||||
const Brush *brush = reinterpret_cast<Brush *>(old_id_iter);
|
||||
if (brush->gpencil_settings && brush->gpencil_settings->material &&
|
||||
/* Don't unpin if this material is linked, then it can be preserved for the new file. */
|
||||
!ID_IS_LINKED(&brush->gpencil_settings->material))
|
||||
{
|
||||
/* Unpin material and clear pointer. */
|
||||
brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED;
|
||||
brush->gpencil_settings->material = nullptr;
|
||||
}
|
||||
}
|
||||
FOREACH_MAIN_LISTBASE_ID_END;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a complete replacement of data in `new_bmain` by data from `old_bmain. Original new data
|
||||
* are moved to the `old_bmain`, and will be freed together with it.
|
||||
@@ -946,6 +969,7 @@ static void setup_app_data(bContext *C,
|
||||
BKE_main_idmap_destroy(reuse_data.id_map);
|
||||
|
||||
if (!params->is_factory_settings && reuse_editable_asset_needed(&reuse_data)) {
|
||||
unpin_file_local_grease_pencil_brush_materials(&reuse_data);
|
||||
/* Keep linked brush asset data, similar to UI data. Only does a known
|
||||
* subset know. Could do everything, but that risks dragging along more
|
||||
* scene data than we want. */
|
||||
|
||||
Reference in New Issue
Block a user