Commit Graph

62 Commits

Author SHA1 Message Date
Bastien Montagne
794c2828af Initial implementation of local ID re-use when appending.
This commit adds to ID struct a new optional 'weak reference' to a
linked ID (in the form of a blend file library path and full ID name).

This can then be used on next append to try to find a matching local ID
instead of re-making the linked data local again.

Ref. T90545

NOTE: ID re-use will be disabled for regular append for the time being
(3.0 release), and only used for assets. Therefore, this commit should
not change anything user-wise.

Differential Revision: https://developer.blender.org/D12545
2021-09-22 16:55:39 +02:00
Bastien Montagne
edb95b3fcb Cleanup: Use ID_IS_LINKED instead of direct id.lib pointer check. 2021-08-26 15:01:14 +02:00
Campbell Barton
cbc671947a Fix T88033: Python reference memory leaks for non main data-blocks
ID data-blocks that could be accessed from Python and weren't freed
using BKE_id_free_ex did not release the Python reference count.

Add BKE_libblock_free_data_py function to clear the Python reference
in this case.

Add asserts to ensure no Python reference is held in situations
when ID's are copied for internal use (not exposed through the RNA API),
to ensure these kinds of leaks don't go by unnoticed again.
2021-08-11 17:10:02 +10:00
Campbell Barton
8e8a6b80cf Cleanup: replace BLI_assert(!"text") with BLI_assert_msg(0, "text")
This shows the text as part of the assertion message.
2021-07-15 18:29:01 +10:00
Campbell Barton
9b89de2571 Cleanup: consistent use of tags: NOTE/TODO/FIXME/XXX
Also use doxy style function reference `#` prefix chars when
referencing identifiers.
2021-07-04 00:43:40 +10:00
Bastien Montagne
fe2ceef729 Fix first part of T86501: Crash during resync process.
Code would end up freeing some of the newly created overrides, which
were assigned to the matching linked ID's `newid` pointer, accessed
again further down the code.

Note that this is not a normal expected situation, and it won't give a
proper resync result anyway, but it might happen in some complicated
corner cases, and also quite often when dealing with older .blend files.
2021-03-12 09:46:11 +01:00
Bastien Montagne
63b7ff9f4e Cleanup: Main foreach ID code: Remove MAX_LIBARRAY and improve comments.
The `MAX_LIBARRAY` define was an annoying doublon to the `INDEX_ID_MAX` enum value
now defined in `DNA_ID.h`, and it is no more useful.

And comments were somewhat outdated. Also added an explanation about
chosen order for the `INDEX_ID_<IDTYPE>` order.
2021-03-04 18:43:30 +01:00
Bastien Montagne
1df6cd67a1 Fix (unreported) bad usercount handling in batch ID deletion.
This was rather obscure and non-critical issue, but in some cases ID
usercount of some deleted IDs from batch-deletion code would not be
properly nullified, which would then assert later in actual deletion
code.
2021-02-25 17:48:54 +01:00
Sybren A. Stüvel
2601501fce RNA: make bpy.data.orphans_purge() return number of deleted datablocks
Sometimes multiple calls to `bpy.data.orphans_purge()` are needed to
delete all orphans, because a call can turn previously-used datablocks
into orphans. Returning the number of deleted datablocks makes it
possible to keep looping until nothing can be deleted any more.

This patch keeps track of deletions in `id_delete()` so that it can be
returned up the call stack.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D9918
2020-12-22 14:05:49 +01:00
Julian Eisel
b71eb3a105 Asset System: Data-block asset metadata storage, reading and API
Asset metadata is what turns a regular data-block into an asset. It is a small
data-structure, but a key part of the technical design of the asset system.

The design foresees that asset data-blocks store an `ID.asset_data` pointer of
type `AssetMetaData`. This data **must not** have dependencies on other
data-blocks or data-block data, it must be an independent unit. That way we can
read asset-metadata from .blends without reading anything else from the file.
The Asset Browser will use this metadata (together with the data-block name,
preview and file path) to represent assets in the file list.

Includes:
* New `ID.asset_data` for asset metadata.
* Asset tags, description and custom properties.
* BKE code to manage asset meta-data and asset tags.
* Code to read asset data from files, without reading IDs.
* RNA for asset metadata (including tags)

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

Differential Revision: https://developer.blender.org/D9716

Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-15 17:03:00 +01:00
Ankit Meel
30ec0753c7 Revert "Fix T81077 id_management test on macOS"
This reverts commit 2ddecfffc3.

The correct fix is to compile with -fno-strict-aliasing on
release/relwithdebinfo builds also.

See the last commit/ {D9372}.

Maniphest Task T81077
2020-10-28 20:54:10 +05:30
Ankit Meel
2ddecfffc3 Fix T81077 id_management test on macOS
This looks like a optimizer bug where it makes wrong assumptions.
The code inside lib_id_delete:264 on rBafd13710b897cc1c11b
`for (id = last_remapped_id->next; id; id = id->next) {..}`
is not executed in release/relwithdebinfo builds.

This can be "fixed" by several ways:
- Adding a line that prints the `last_remapped_id->name` right before
  the said for-loop starts.
- Turning off optimization for the whole function `id_delete`:
  `#pragma clang optimize off/on` Ray Molenkamp
- Marking `last_remapped_id` volatile. Julian Eisel
- Marking `tagged_deleted_ids` volatile. But it adds a warning when
  calling `BLI_addtail`: discards volatile qualifier. Discovered by
  accident.

Fix T81077

Reviewed By: mont29

Maniphest Tasks: T81077

Differential Revision: https://developer.blender.org/D9315
2020-10-26 15:02:20 +05:30
Philipp Oeser
cd81c38688 Cleanup: typo in comment 2020-10-01 18:38:31 +02:00
Campbell Barton
c2419cdc5e Fix T80238: Crash adding properties to material node-trees
The localized node-tree was freeing the materials ID properties twice.

This matches how animation data behaves, setting to NULL after freeing.
2020-09-08 18:09:22 +10:00
Bastien Montagne
a5ded0720c Fix (unreported) broken deletion of Shapekeys alongside their owner ID.
Trying to get shape key pointer after having unlinked its owner from
Main data-base is rather useless... So those shapekeys ended up never
being deleted.
2020-07-20 19:18:45 +02:00
Bastien Montagne
febb2351ad Fix ShapeKeys not being deleted together with their owner ID.
Consistency with e.g. copying (copying a mesh also duplicates its
shapekey typically).

Baby step towards getting rid of this horrible ID, some day...

Note that for now we only do that when taking BMain into account, fancy
code dealing with non-main IDs and such has to deal with those itself.
2020-06-29 17:28:04 +02:00
Campbell Barton
20c25bffda Merge branch 'blender-v2.83-release' 2020-05-15 17:47:58 +10:00
Campbell Barton
6a850f3cc8 Fix duplicate ID's being created when appending/linking
This removes grease pencil brush creation/dat-block delete on load,
since this causes duplicate data-blocks.

Add assert to prevent this happening in the future
since the error is isn't obvious.
2020-05-15 17:42:01 +10:00
Brecht Van Lommel
ec14bee20d Cleanup: remove unused includes 2020-04-21 14:57:19 +02:00
Sybren A. Stüvel
3208454aa8 Cleanup: Animation, move AnimData API to anim_data.c/BKE_anim_data.h
The `BKE_animsys.h` and `anim_sys.c` files already had a an "AnimData
API" section. The code in that section has now been split off, and
placed into `BKE_anim_data.h` and `anim_data.c`.

All files that used to include `BKE_animsys.h` have been adjusted to
only include the animation headers they need (sometimes none).

No functional changes.
2020-04-03 16:46:48 +02:00
Dalai Felinto
2d1cce8331 Cleanup: make format after SortedIncludes change 2020-03-19 09:33:58 +01:00
Bastien Montagne
be2e41c397 Cleanup: Move BKE_animdata_free() call out of each IDType free data.
This has been long standing TODO...

Note that remaining usages of BKE_xxx_delete should all be carefully
checked for and utilmately nuked in favor of `BKE_id_delete()`, think we
still have quiet a few bugs hidden in those (code seems to usually
assume those functions do a full ID deletion, which is not the case).
2020-03-09 18:43:11 +01:00
Bastien Montagne
6472a721f0 Cleanup: Remove unused switch/case from BKE_lib_id.
Only covers direct usages of new callbacks from IDTypeInfo.

We still have a lot of those switch/case, many can probably go away
with minimal refactor now, but that will be for later.
2020-03-09 18:43:11 +01:00
Bastien Montagne
e672cf11c3 Cleanup: palette: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 18:09:23 +01:00
Bastien Montagne
3e9dbe7f62 Cleanup: GreasePencil: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 18:09:23 +01:00
Bastien Montagne
c010290e75 Cleanup: Ipo: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 18:09:23 +01:00
Bastien Montagne
4d0d43ce8e Cleanup: FreestyleLineStyle: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 16:56:53 +01:00
Bastien Montagne
dab1d14a51 Cleanup: Mask: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 16:56:53 +01:00
Bastien Montagne
6965bcc0c9 Cleanup: MovieClip: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 16:56:53 +01:00
Bastien Montagne
3a10c61a7d Cleanup: ParticleSettings: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 12:49:04 +01:00
Bastien Montagne
b9d1026ce0 Cleanup: PaintCurve: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 12:49:04 +01:00
Bastien Montagne
b57d3afb76 Cleanup: CacheFile: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 12:49:04 +01:00
Bastien Montagne
613148ce5b Cleanup: WorkSpace: Move to IDTypeInfo and remove unused BKE API. 2020-03-09 12:49:04 +01:00
Bastien Montagne
0de5156a24 Cleanup: WindowManager: Move to IDTypeInfo and remove unused WM API.
Getting rid of one static 'registered' callback in BKE, yeah!
2020-03-09 12:49:04 +01:00
Bastien Montagne
668b64380a Cleanup: Sound: Move to IDTypeInfo and remove unused BKE API. 2020-03-08 20:45:00 +01:00
Bastien Montagne
014f78b5b5 Cleanup: Speaker: Move to IDTypeInfo and remove unused BKE API. 2020-03-08 20:10:07 +01:00
Dalai Felinto
afe6df1487 Cleanup: VFont: Move to IDTypeInfo and remove unused BKE API
This was particularly strange because we had a _free_data() function.
But still the one I replaced was of course the _free() one.

And we should rename the _free_data_ function later to avoid confusions.
2020-03-06 20:07:02 +01:00
Dalai Felinto
558f449f8c Cleanup: Text: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 20:07:02 +01:00
Bastien Montagne
b825a95ec3 Cleanup: Image: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 17:13:27 +01:00
Bastien Montagne
f4936de918 Cleanup: Texture: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 17:13:27 +01:00
Bastien Montagne
a7fb567c18 Cleanup: Material: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 17:13:27 +01:00
Dalai Felinto
68b6d0302a Cleanup: Action: Move to IDTypeInfo, and remove unused BKE API. 2020-03-06 16:43:09 +01:00
Dalai Felinto
57daecc2cf Cleanup: Armature: Move to IDTypeInfo, and remove unused BKE API. 2020-03-06 16:43:09 +01:00
Bastien Montagne
b242cc6792 Cleanup: Lattice: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 16:23:23 +01:00
Bastien Montagne
da7fcd3e52 Cleanup: MetaBall: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 16:23:23 +01:00
Bastien Montagne
8c21668ee1 Cleanup: Curve: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 16:23:23 +01:00
Bastien Montagne
bf6cf49133 Cleanup: Mesh: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 16:23:23 +01:00
Dalai Felinto
17f08cff6a Cleanup: Collection: Move to IDTypeInfo, and remove unused BKE API.
Note: we still need BKE_collection_free since we call it from scene.c.
2020-03-06 15:27:50 +01:00
Bastien Montagne
b201a67faa Cleanup: bScreen: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 15:20:04 +01:00
Bastien Montagne
f9c7442479 Cleanup: bNodeTree: Move to IDTypeInfo and remove unused BKE API. 2020-03-06 14:58:23 +01:00