Commit Graph

183 Commits

Author SHA1 Message Date
Campbell Barton 4fc5d287ac Cleanup: doxygen parameters, blank comment lines 2023-09-08 16:53:30 +10:00
Bastien Montagne e20a284cb9 Fix #111488: Copying object crashes Blender after recent refactor.
Caused by 8bb5916183.

Trivial mistake, would have been caught by a basic test, so also added
said test for the 'write partial' feature.
2023-08-25 11:04:03 +02:00
Bastien Montagne 28305c2c73 Refactor: Properly formalize special versioning done after most of readfile code.
In a few cases (IPO conversion, Proxy conversion, ...), versioning
implies creating or removing IDs, and/or needs access to the whole Main
data-base.

So far this was done ad-hoc by adding some code at the end of
`setup_app_data`.

This commit formalizes this process by adding a BLO call
(`BLO_read_do_version_after_setup`) that will encapsulate all such
complex versioning code.

NOTE: This commit does not address the existing issue that this
versioning code is never performmed when linking new data (outside of
the 'opening a blendfile' context). This topic would require its own
design task.

NOTE: This commit does not fix the few current evil cases of ID creation in
regular versioning code. This will be addressed separately.

Although this commit does modifies slightly some logic in this specific
versioning process, no behavioral changes are expected here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111147
2023-08-16 16:21:59 +02:00
Julian Eisel 9b246fc438 Merge branch 'blender-v3.6-release' 2023-06-19 16:40:10 +02:00
Julian Eisel 232e065a17 Fix #109053: File Append with recursions leads to crash
In this specific code path (recursive reading inside .blend files
containing assets), reading datablocks marked as asset would move
ownership over the asset metadata without indicating that in the source
that owned it previously. This would cause a double free attempt.
2023-06-19 16:39:37 +02:00
Bastien Montagne 7ef8389dad Fix #108746: Defaults / Save startup file don't save the window size.
Hopefully now the behavior is fully consistent with before the refactor,
current implemented one by this commit:

- When loading factory settings file on startup, go full-screen.
- In all other startup cases, use size as stored in the startup .blend
  file.

Regression from ebb5643e59 and 32bbfbb06e.
2023-06-09 11:29:15 +02:00
Campbell Barton 9c28eebc9a Cleanup: minor clarifications & corrections, use doxygen comments
Also replace full URL's in with #ID.
2023-06-08 10:43:55 +10:00
Campbell Barton abca216a1d Cleanup: use C++ comments for disabling code
[0] used doxygen comment to disable code. Use '//' instead &
move the old doc-string to the newly added flag.

[0]: 7dc85e68fe
2023-06-08 10:32:00 +10:00
Bastien Montagne 32bbfbb06e Fix #108643: Blender window does not open to full dimensions of the desktop.
When opening 'homefile' (i.e. startup or factory startup) at Blender
start (i.e. when there is no existing WM yet), the size of the windows
in the newly read WM is reset to zero, which will then cause `WM_check`
to re-size them the the maximum possible size on current monitor.

Regression from ebb5643e59.
2023-06-07 20:01:11 +02:00
Campbell Barton 6704881708 Cleanup: spelling in comments 2023-06-07 21:47:45 +10:00
Bastien Montagne ebb5643e59 Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
  opening a .blend file.

While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.

Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).

This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).

From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
  - Prevent WM code from doing (too much) horrible ID 'management' on
    its WM when opening a new file. It used to remove current WM from
    the Main database, store it in a temporary own list, and then free
    it itself...
  - Trying to make the complex logic behind WM handling on file reading a
    bit more easy to follow, at least way more documented in code.
  - Keep the handling of 'IDs being re-used from old Main' in a single
    place, as much as possible:
    -- Readfile code itself in undo case (because it's more efficient,
       and undo case is in a way simpler than actual .blend file
       reading case). The whole `blo_lib_link_restore` block of code
       is also removed.
    -- (Mostly) setup_app_data code in actual file reading case.
  - Sanitize the usage of the 'libmap' in readfile code in undo case
    (waaaaay too many pointers were added there, which was hiding some
     other issues in the related code, and potentially causing (in
     rare cases) memory addresses collisions.

Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 13c815085b Cleanup: spelling in comments 2023-05-24 11:21:18 +10:00
Julian Eisel 48814c25fd Cleanup: Move blend file path utilities out of blenloader module
These are not really about reading or writing .blend files, they are
general utilities for file-names/paths. Having to link to the
blendloader library just for these utilities is annoying.
Moved them to `BKE_blendfile.h` now, in agreement with Bastien.

Pull Request: #105825
2023-03-16 15:07:27 +01:00
Bastien Montagne b3f42d8e98 Add a mechanism to abort a blend file reading on critical error.
This commit introduces a new Main boolean flag that marks is as invalid.

Higher-level file reading code does checks on this flag to abort reading
process if needed.

This is an implementation of the #105083 design task.

Given the extense of the change, I do not think this should be
considered for 3.5 and previous LTS releases.
2023-03-01 11:50:50 +01:00
Jacques Lucke 4bef5f3df7 Cleanup: move some undo related files to C++
For continued testing in D14139. Also see T103343.
2023-01-23 00:33:55 +01:00
Campbell Barton 60d9de767d Cleanup: remove redundant forward declarations for structs 2023-01-18 18:41:13 +11:00
Julian Eisel 6a7917162c Fix asset index only generating empty entries since 1efc94bb2f
Steps to reproduce were:
- Open a .blend file that is located inside of an asset library and
  contains assets.
- Save and close the file.
- Open a new file (Ctrl+N -> General).
- Open asset browser and load the asset library from above.
- If the assets from the file above still show up, press refresh button.
- -> Assets from the file above don't appear.

Likely fixes the underlying issue for T102610. A followup will be needed
to correct the empty asset index files written because of this bug.

We're in the process of moving responsibilities from the file/asset
browser backend to the asset system. 1efc94bb2f introduces a new
representation for asset, which would own the asset metadata now instead
of the file data.

Since the file-list code still does the loading of asset libraries,
ownership of the asset metadata has to be transferred to the asset
system. However, the asset indexing still requires it to be available,
so it can update the index with latest data. So transfer the ownership,
but still keep a non-owning pointer set.

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

Reviewed by: Bastien Montagne
2022-12-02 14:48:51 +01:00
Julian Eisel 489260198e File Browser: Fix slowdown with non-existing ID previews in big files
When the File (or Asset) Browser would display data-blocks without
previews in a heavy .blend file, there would be a drastic slowdown.

See patch for details and comparison videos.

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

Reviewed by: Bastien Montagne
2022-10-18 15:10:59 +02:00
Campbell Barton 6c6a53fad3 Cleanup: spelling in comments, formatting, move comments into headers 2022-09-06 16:25:20 +10:00
Campbell Barton 5c9ab3e003 Cleanup: use term 'filepath' for full file paths 2022-05-17 12:54:05 +10:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Bastien Montagne 049df7ef94 Proxies Removal: Handle conversion to liboverrides also for linked data.
So far linked proxies were just kept as-is, this is no longer an option.

Attempt to convert them into liboverrides as much as possible, though
some cases won't be supported:
- Appending proxies is broken since a long time, so conversion will fail
  here as well.
- When linking data, some cases will fail to convert properly. in
  particular, if the linked proxy object is not instanced in a scene
  (e.g. when linking a collection containing a proxy as an
  epty-instanced collection instead of a view-layer-instanced collection).

NOTE: converion when linking/appending is done unconditionnaly, option
to not convert on file load will be removed in next commit anyway.

Part of T91671.
2022-02-02 09:47:10 +01:00
Campbell Barton 3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Campbell Barton a207c1cdaf Cleanup: resolve parameter mis-matches in doc-strings
Renamed or removed parameters which no longer exist.
2021-12-14 18:35:23 +11:00
Campbell Barton 8ad2642c47 Cleanup: use "filepath" term for Main, BlendFileData & FileGlobal
Use "filepath" which is the current convention for naming full paths.

- Main use "name" which isn't obviously a file path.
- BlendFileData & FileGlobal used "filename" which is often
  used for the name component of a path (without the directory).
2021-12-13 16:22:19 +11:00
Campbell Barton 4f48b2992b Cleanup: move public doc-strings into headers for 'blenloader'
Ref T92709
2021-12-08 17:51:45 +11:00
Bastien Montagne 9f290467ca Blendread: Remove all instantiation logic from `BLO_library_link_` code.
Instantiation is now fully handled by BKE_blendfile_link_append module.

Note that this also allows removal of the `BLO_LIBLINK_NEEDS_ID_TAG_DOIT`
flag.

Part of T91414: Unify link/append between WM operators and BPY context
manager API, and cleanup usages of `BKE_library_make_local`.
2021-12-02 11:10:34 +01:00
Bastien Montagne 4fe8c62b56 Cleanup: Readfile: Remove deprecated `BLO_library_link_copypaste`.
Rewrite of ID paste code in rB3f08488244c0 made this function useless,
ID pasting is now handled by the BKE_blendfile_link_append module too.
2021-12-02 10:27:34 +01:00
Bastien Montagne 059da44fbc BKE Link/Append: Use BLO's LibraryLink_Params.
This allows to reduce signature of several functions, and make it eaiser
to integrate more higher-level usages later on.

This should be a non-behavioral-change commit.

Part of T91414: Unify link/append between WM operators and BPY context
manager API, and cleanup usages of `BKE_library_make_local`.
2021-11-22 17:14:21 +01:00
Campbell Barton d612d92630 Cleanup: use term sequence_strip instead of vse_strip 2021-11-12 17:38:58 +11:00
Bastien Montagne 641a5be50e IDManagement: Add option to clear asset data when making ID local.
When appending an asset from the asset browser, its asset data needs to
be cleared.

However, linking an asset (or regular append from the file browser)
should not clear such data. In linking case, it would be there again
after a blend file reload anyway.

So this commit introduces a new `BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR`
option.

NOTE: in case the appended ID needs to be copied from its linked data
(instead of making the later directly local), asset data is lost anyway
since it is never copied with the ID currently.

Ref. {T91749} and D11768.
2021-10-21 12:55:15 +02:00
Campbell Barton 063c4e467d Cleanup: de-duplicate function to instantiate objects
De-duplicates wm_append_loose_data_instantiate_object_base_instance_init
and object_base_instance_init.

Add BLO_object_instantiate_object_base_instance_init which also adds to
a collection since all callers did this.
2021-10-21 16:57:53 +11:00
Campbell Barton 93197c4660 Cleanup: spelling in comments 2021-10-20 09:19:21 +11:00
Bastien Montagne b3b7319de7 Fix T92224: Refactor of append code unexpectedly changed behavior with 'localize all' off.
In 2.93 and before, when appending wityh 'localize all' off, all linked
IDs (including indirectly linked ones) from initial library would be
made local.
In 3.0, after refactor from rB3be5ce4aad5e, only directly linked IDs
(i.e. user-selected IDs) would be made local.

This change was not intentional (result of confusing code and naming in
previous implementation), and old behavior is used in some workflows to
control which data is kept linked and which data is made local.

This commit revert to 2.93 behavior.

NOTE: there is still an (extreme) corner case where behavior is
different between 2.93 and 3.0:
If you append (at the same time) object A from LibA.blend, and object B
from LibB.blend, and object B uses somehow a material from LibA.blend:
* In 2.93, that material would have been made local (because it belonged
  to one of the 'initial' libraries, even though not the initial lib of
  object B).
* In 3.0, this material will remain linked, since from object B
  persective it comes from a different library.
2021-10-19 16:26:26 +02:00
Jeroen Bakker e659f78d3e Cleanup: use typedef struct for BLODataBlockInfo. 2021-10-13 15:44:36 +02:00
Campbell Barton 74f45ed9c5 Cleanup: spelling in comments 2021-10-03 12:13:29 +11:00
Dalai Felinto a64782b133 VSE: Implement sanity check for files with more channels than supported
This is a follow up to 8fecc2a852.

This makes sure future .blend files that have more channels than the
limit won't break Blender.

It can be backported to LTS.

This is part of https://developer.blender.org/D12645

Differential Revision: https://developer.blender.org/D12648
2021-09-28 10:23:13 +02:00
Bastien Montagne 501b0190d6 LibOverride: Deprecate Proxies: Add auto-conversion on file load.
This commit also add an experimental userPreferences to prevent proxies
conversions on file load, and reporting for amount of coverted proxies
(and possible issues).

Note that potentially linked proxies from other libraries are not
hamdled here (this feature seems to be broken anyway in master
currently?).
2021-09-24 12:40:04 +02:00
Jeroen Bakker fc7beac8d6 FileBrowser: Reduce Overhead Browsing Libraries.
When Browsing libraries the asset files were opened multiple times.
once to determine the needed groups to query and once for each
group to query the items in the group. For file browsing this makes sense
but for asset browsing this can be reduced.

This patch will load the asset files recursively and only opens them once.
Another change is that only the assets are requested and not filtered out
later in the process.

This patch is needed to simplify the library indexing. Where
we need access to the full library content.

## The numbers ##

Benchmarked by adding scenes of the spring open movie to the default
asset library. Refreshing the asset library would recursively load all the files
there.

| **8bc27c508a** | Processed 317 'directories/libraries' | 7.573986s |
| **Patch** | Processed 42 'directories/libraries' | 0.821013s |

{F10442811}

Reviewed By: mont29, Severin

Maniphest Tasks: T91406

Differential Revision: https://developer.blender.org/D12499
2021-09-24 08:41:40 +02:00
Campbell Barton b659d1a560 Cleanup: spelling in comments 2021-09-23 22:08:02 +10:00
Bastien Montagne f48a4aa0f9 LibLink Append: Expose 'reuse ID' through new BLO flag, and add basic tests.
Option is now available to append operator, alsthough hidden and
disabled by default.
2021-09-23 12:56:05 +02:00
Bastien Montagne ce96a75c2c Cleanup: eBLOLibLinkFlags: Add 'space' between `APPEND` flags and `INSTANCE` ones. 2021-09-23 12:45:40 +02:00
Bastien Montagne 3042994c91 Link/Append: Refactor flags.
Flags controlling link/append code are split between two enums, one in
`DNA_space_types.h` and one in `BLO_readfile.h`.

This commit:
 - Moves flags exclusively used in WM and BLO code to `eBLOLibLinkFlags`
   in `BLO_readfile.h`. Flags in `eFileSel_Params_Flag` from
   `DNA_space_types.h` are now only the ones effectively used by the
   file browser editor code too.
 - Fixes some internal utils in `readfile.c` still taking `short` flag
   parameter instead of proper `int` one.

NOTE: there are a few other flags that could probably be moved to
`eBLOLibLinkFlags` (at the very least `FILE_LINK`, probably also
`FILE_AUTOSELECT` and `FILE_ACTIVE_COLLECTION`), since those are not
effectively used by the file browser, and control linking/appending
behavior, not filebrowser behavior.

However for now think it's safer to not touch that.
2021-09-23 11:01:00 +02:00
Jeroen Bakker 0fd1e6a5f4 T90908: Reduce loading times when extracting thumbnails from Blendfiles.
Previously when loading an thumbnails for an asset the whole file was
read. Reason this was done was perhaps a future idea to load
all thumbnails inside a blendfile in a single go. This was never implemented
and currently unneeded disk and cpu cycles was spend with finding out what
preview to load.

This patch adds an early break when the thumbnail that the caller is
interested in has been found. This improves the thumbnail extraction
when looking into large files.

Reviewed By: mont29

Maniphest Tasks: T90908

Differential Revision: https://developer.blender.org/D12312
2021-08-25 15:59:41 +02:00
Bastien Montagne bb0e29c922 Blendloader: Option to reports to skip list of recursively liboverride-resynced libs.
This extra info is not always needed/convinient to use, and requires
special attention to free the list, so allow not generating it.
2021-08-13 16:37:29 +02:00
Bastien Montagne 20d5d7b8ec Blender Readfile: Fix annoying useless Object reading error messages.
Extend the 'reading error' container to produce the generic short
message in the popup directly visible by the user, and move all detailed
info the `INFO` reports that only show up in the console and Info
editor.
2021-08-03 12:54:05 +02: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 8cdb99d51c Fix linking code after own recent commit.
More stupid mistake in recent enhanced reports for file load code,
rB82c17082ba0e left some read-after-free situations.
2021-06-24 12:10:06 +02:00
Campbell Barton 55bffa82da Cleanup: clang-format, spelling 2021-06-24 15:53:26 +10:00