Commit Graph

64 Commits

Author SHA1 Message Date
Bastien Montagne
48e26c3afe MEM_guardedalloc: Refactor to add more type-safety.
The main goal of these changes are to improve static (i.e. build-time)
checks on whether a given data can be allocated and freed with `malloc`
and `free` (C-style), or requires proper C++-style construction and
destruction (`new` and `delete`).

* Add new `MEM_malloc_arrayN_aligned` API.
* Make `MEM_freeN` a template function in C++, which does static assert on
  type triviality.
* Add `MEM_SAFE_DELETE`, similar to `MEM_SAFE_FREE` but calling
  `MEM_delete`.

The changes to `MEM_freeN` was painful and useful, as it allowed to fix a bunch
of invalid calls in existing codebase already.

It also highlighted a fair amount of places where it is called to free incomplete
type pointers, which is likely a sign of badly designed code (there should
rather be an API to destroy and free these data then, if the data type is not fully
publicly exposed). For now, these are 'worked around' by explicitly casting the
freed pointers to `void *` in these cases - which also makes them easy to search for.
Some of these will be addressed separately (see blender/blender!134765).

Finally, MSVC seems to consider structs defining new/delete operators (e.g. by
using the `MEM_CXX_CLASS_ALLOC_FUNCS` macro) as non-trivial. This does not
seem to follow the definition of type triviality, so for now static type checking in
`MEM_freeN` has been disabled for Windows. We'll likely have to do the same
with type-safe `MEM_[cm]allocN` API being worked on in blender/blender!134771

Based on ideas from Brecht in blender/blender!134452

Pull Request: https://projects.blender.org/blender/blender/pulls/134463
2025-02-20 10:37:10 +01:00
Pratik Borhade
a03dd37dfe Merge branch 'blender-v4.4-release' 2025-02-18 15:18:23 +05:30
Pratik Borhade
73a9a024f9 Fix #134380: Error adding a torus after hiding a collection
This reverts 06a2617107.
Commit has introduced few errors from user perspective (#134277) and
python side (#134380). Best to revert it now then handle the bug fixes later.

The error in #134380 was due to `context.layer_collection` and
`active_layer_collection` returning excluded collection.

Pull Request: https://projects.blender.org/blender/blender/pulls/134546
2025-02-18 10:05:59 +01:00
Bastien Montagne
87a4c0d3a8 Refactor: Make Library.runtime an allocated pointer.
Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.

Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
  * Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
  dedicated utils, `search_filepath_abs`, instead of using
  `BLI_findstring`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134188
2025-02-07 17:47:16 +01:00
Hans Goudey
7d6e098ca1 Cleanup: Remove unused includes in blenkernel
Pull Request: https://projects.blender.org/blender/blender/pulls/133688
2025-01-28 15:27:34 +01:00
Pratik Borhade
06a2617107 Fix #100786: Collection hide viewport in properties tab
Similar to other visibility properties, include "hide_viewport" in
collection properties tab. One issue is that, when collection is
disabled, automatically parent collection is selected or tab is gone
when parent collection does not exist. The check was added in
0a903e7ab1, it doesn't seem very useful so
removed that.

Pull Request: https://projects.blender.org/blender/blender/pulls/132107
2025-01-10 14:49:43 +01:00
Hans Goudey
f2c9fccee0 Cleanup: Move legacy node integer types defines to separate header
Moving these defines to a separate header makes their "legacy" status
more obvious. This commit just adds the include wherever necessary.

Followup to 971c96a92c.

Pull Request: https://projects.blender.org/blender/blender/pulls/132875
2025-01-09 20:03:08 +01:00
Jacques Lucke
971c96a92c Nodes: rename integer type of nodes to type_legacy
The new description for `bNode.type_legacy`:
```
  /**
   * Legacy integer type for nodes. It does not uniquely identify a node type, only the `idname`
   * does that. For example, all custom nodes use #NODE_CUSTOM but do have different idnames.
   * This is mainly kept for compatibility reasons.
   *
   * Currently, this type is also used in many parts of Blender, but that should slowly be phased
   * out by either relying on idnames, accessor methods like `node.is_reroute()`.
   *
   * A main benefit of this integer type over using idnames currently is that integer comparison is
   * much cheaper than string comparison, especially if many idnames have the same prefix (e.g.
   * "GeometryNode"). Eventually, we could introduce cheap-to-compare runtime identifier for node
   * types. That could mean e.g. using `ustring` for idnames (where string comparison is just
   * pointer comparison), or using a run-time generated integer that is automatically assigned when
   * node types are registered.
   */
```

Pull Request: https://projects.blender.org/blender/blender/pulls/132858
2025-01-09 15:28:57 +01:00
Sergey Sharybin
a2f825fde5 Cleanup: Strict compiler warning in release mode
Fixes warning: unused variable 'no_resync_recurse_max' [-Wunused-const-variable]
2024-07-17 14:31:48 +02:00
Bastien Montagne
9b8001f370 BKE Layers: make 'no_resync' flag re-entrant and thread-safe.
This commit allows re-entrant calls to
`BKE_layer_collection_resync_forbid` and
`BKE_layer_collection_resync_allow`, such that higher-level code can
block layer collections updates while calling lower-level code that does
the same thing.

E.g. `BKE_id_delete` blocks and then re-allows such updates. However,
such code can also be called from other pieces of code that also need
to prevent these updates in their own, broader scope.

In addition, realized that this call had concurrency issues since BKE
code using it is called from non-main thread too (e.g. from depsgraph
evaluation).

So made the counter atomic to ensure all calls to
`BKE_layer_collection_resync_forbid` is matched by a call to
`BKE_layer_collection_resync_allow`. Also added a cap to max amount of
're-entrant' calls (has to be quite high, due to potential concurrent
calls too).

This is required to fix #124777.
2024-07-17 12:57:47 +02:00
Jesse Yurkovich
9d8a90d53c Fix: Disable collection export for linked collections
If a non-instanced collection is linked, any collection exporters on the
linked collection would be active and invokable. This is probably not
desired as it could inadvertently overwrite files from the original.
Disable the operators in this case.

See PR for how each of the various append/link scenarios behave.

Pull Request: https://projects.blender.org/blender/blender/pulls/123149
2024-06-21 20:52:18 +02:00
Brecht Van Lommel
a926f5b67d Refactor: Replace ID_IS_LINKED by !ID_IS_EDITABLE
Add new ID_IS_EDITABLE macro that checks if the ID can be edited in the
user interface. Replace usage of ID_IS_LINKED where it is used with this
meaning.

Also add a corresponding ID.is_editable property for Python.

This prepares for the ability to edit some linked datablocks for brush
assets.

Pull Request: https://projects.blender.org/blender/blender/pulls/121838
2024-05-16 14:53:09 +02:00
Brecht Van Lommel
1420c7bc60 Fix: Crash when ViewLayer.active_collection is invalid in blend file
Pull Request: https://projects.blender.org/blender/blender/pulls/121035
2024-04-24 17:42:18 +02:00
Brecht Van Lommel
15b9ae5436 Refactor: Use typed functions for blend file data reading
This makes the read and write API functions match more closely, and adds
asserts to check that the data size is as expected.

There are still a few places remaining that use BLO_read_data_address
and similar generic functions, these should eventually be replaced as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/120994
2024-04-24 17:01:22 +02:00
Jesse Yurkovich
509a7870c3 Collection Exporters: Enable file exporters to be specified on Collections
This implements the ability to have file exporters added and configured on Collections.

Exporting is reachable from several locations:
- Individually on each exporter configuration: The `Export` button in each panel header
- For all exporters on the collection: The `Export All` button in the main panel interface
- For all exporters on all collections in the scene: The `File`->`Export All Collections` button

Visibility of which collections currently have exporters configured is done by ways of an icon added to the Collection row in the Outliner.

Adding multiple exporters for the same file type is permitted. The user is free to setup several exports of the same format but with different file locations or settings etc.

Notes:
Only USD and Wavefront OBJ are enabled for the initial commit. Additional formats, including those implemented in Python will be added as separate commits after this.

Ref #115690
Pull Request: https://projects.blender.org/blender/blender/pulls/116646
2024-04-08 22:10:39 +02:00
Campbell Barton
7e5a712e58 Cleanup: remove redundant null pointer checks
Based on the surrounding context these checks aren't needed.
2024-04-01 22:20:09 +11:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Hans Goudey
81a63153d0 Despgraph: Rename "copy-on-write" to "copy-on-evaluation"
The depsgraph CoW mechanism is a bit of a misnomer. It creates an
evaluated copy for data-blocks regardless of whether the copy will
actually be written to. The point is to have physical separation between
original and evaluated data. This is in contrast to the commonly used
performance improvement of keeping a user count and copying data
implicitly when it needs to be changed. In Blender code we call this
"implicit sharing" instead. Importantly, the dependency graph has no
idea about the _actual_ CoW behavior in Blender.

Renaming this functionality in the despgraph removes some of the
confusion that comes up when talking about this, and will hopefully
make the depsgraph less confusing to understand initially too. Wording
like "the evaluated copy" (as opposed to the original data-block) has
also become common anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/118338
2024-02-19 15:54:08 +01:00
Bastien Montagne
e71ae3b16c Cleanup: Move BKE_collection.h to CPP header. 2024-02-09 19:42:38 +01:00
Bastien Montagne
45e7827898 Clenup: Move BLT headers to Cpp.
Noisy but fairly straight forward.
2024-02-09 18:59:42 +01:00
Hans Goudey
02582213de Cleanup: Move BKE_layer.hh to C++ 2024-01-24 10:55:16 -05:00
Campbell Barton
5574a2790f Cleanup: rename uuid to uid for local-view functionality
Follow up to 311ca3e6af.
2024-01-23 16:07:39 +11:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Hans Goudey
5b55c1dc10 Cleanup: Move five draw headers to C++ 2024-01-05 13:26:22 -05:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Bastien Montagne
b840ba1f59 Fix (unreported) crash when trying to link/append while a linked scene is active.
Link/append code sets the scene pointer to `null` when the active
scene is a linked one, to avoid attempt to instantiate linked data
(objects or collections) into a linked scene, which is forbidden.

However, code was still calling some functions expecting a valid scene
pointer, leading to crash.

It is unclear when exactly this issue was introduced code wise. From a
user perspective, it seems to have been revealed between 3.6 and 4.0
release (bisect points at 00a36cbf24, which does not seem to be
directly related...).

In any case, the fix is trivial and safe, so should we do another 4.0
bugfix release, this commit should be backported.
2023-12-13 18:34:13 +01:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Hans Goudey
4bcdc57fc8 Refactor: Move object runtime data to separate allocation
Move object runtime data to a separate header and allocate it separately
as `blender::bke::ObjectRuntime`. This is how node, mesh, curves, and
point cloud runtime data is stored.

Benefits:
- Allow using C++ types in object runtime data
- Reduce space required for Object struct in files
- Increase conceptual separation between DNA and runtime data
- Remove the need to add manual padding in runtime data
- Include runtime struct definition only in files that require it

Pull Request: https://projects.blender.org/blender/blender/pulls/113957
2023-11-15 18:46:07 +01:00
Sergey Sharybin
85c557ffa2 Cleanup: Rename BLI_string_utils.h to BLI_string_utils.hh
All users of it are now C++, which opens doors to add C++ to the
public API.
2023-10-20 10:27:26 +02:00
Hans Goudey
976eaae02f Cleanup: Move BKE_object.hh to C++
Simplifies the fix to #111120, where the object bounds functions
may return a C++ type instead of `BoundBox`.

Pull Request: https://projects.blender.org/blender/blender/pulls/113462
2023-10-09 23:41:53 +02:00
Hans Goudey
867f99c2af Cleanup: Move depsgraph headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/110816
2023-09-22 03:18:17 +02:00
Jacques Lucke
11b2ac54a6 Fix #111166: crash when enabling render pass with equally named AOV
There were two issues:
* The check for conflicting AOVs was done after the Render Layer node
  was updated. This led to an unexpected state in the node.
* The check for conflicting AOVs did not work, because AOVs that already
  had the conflict-flag set were ignored.
2023-09-14 11:26:25 +02:00
Hans Goudey
3db523ab3e Cleanup: Move BLO headers to C++
Except for BLO_readfile.h, which is still included by C files.

Pull Request: https://projects.blender.org/blender/blender/pulls/111610
2023-08-28 15:01:05 +02:00
Campbell Barton
7074c210cc Cleanup: format 2023-08-25 09:40:42 +10:00
Bastien Montagne
b53c7a804a Readfile: Replace the 'lib_link' specific code by generic usage of foreach_id.
The `lib_link` callback cannot always be fully replaced/removed, as in
some case it is also doing some validation checks, or data editing based
on the result of lib_linking internal ID pointers.

The callback has been renamed for that purpose, from `read_lib` to
`read_after_liblink`. It is now called after all ID pointers have been
fully lib-linked for the current ID, but still before the call to
`do_versions_after_linking`.

This change should not have any behavioral effect. Although in theory
the side-effect of this commit (to split lib linking itself, and the
validation/further processing code) into two completely separated steps
could have some effects, in practice none are expected, and tests did
not show any changes in behavior either..

Part of implementing #105134: Removal of readfile's lib_link & expand code.
2023-08-24 16:33:31 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Bastien Montagne
23835a393c Remove compatibility code for blendfiles from early 2.80 development era.
Remove the 'SceneCollection' structure definition from DNA, and the
compatibility code converting it to the 'modern' viewlayer system.

'SceneCollection' was part at some point of the new collection system
during 2.80 development, but was never in any published Blender release.
So this code was only ensuring compatibility with a few potential
Blender files saved from in-development builds over four years ago.

Implements #110918.

Pull Request: https://projects.blender.org/blender/blender/pulls/110926
2023-08-09 11:15:27 +02:00
Campbell Barton
adf58a77ff Cleanup: use LISTBASE_FOREACH & LISTBASE_FOREACH_BACKWARD macros 2023-08-04 08:51:13 +10:00
Campbell Barton
9753e70e37 Cleanup: move BLI_str_replace into BLI_string_utils.h
String search & replace is a higher level function (unlike BLI_string.h)
which handlers lower level replacements for printing and string copying.

Also use BLI_string_* prefix (matching other utilities).

This makes it possible to use BLI_string in Blender's internal utilities
without depending on DynStr, MemArena... etc.
2023-07-04 12:02:25 +10:00
Campbell Barton
69aee8ba6b Cleanup: remove redundant (void) for functions with no args in C++ 2023-07-02 19:54:27 +10:00
Campbell Barton
c1ac3621a9 Cleanup: replace list-base count_at_most with is_single for clarity 2023-06-05 12:42:46 +10: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
8925ea1890 Merge branch 'blender-v3.6-release' 2023-05-20 21:18:02 +10:00
Campbell Barton
bf36a61e62 Cleanup: spelling in comments & some corrections 2023-05-20 21:17:09 +10:00
Bastien Montagne
a9193a9ad2 Refactor ID liblinking on readfile to take ID pointer.
The usage of the lib pointer was cryptic to say the least, it was
essentialy used to allow or not local IDs results in the mapping
old_id_pointer -> new_id_pointer lookup result.

Now:
- Explicitely pass a boolean to allow or not local ID as result in
  lower-level code.
- Pass the 'self ID' pointer instead of its library to the whole
  liblinking code (that was already the case in a few places).

Note that naming of the 'self id' pointer is currently very inconsistent
throughout the readfile liblink code, this will have to be cleaned up in
a separate step later. For now, `self_id` has been chosen for new code
as it matches the terminology in lib_query code.

The later change can also allow finer handling of lookup on undo, based
on how it was re-read (or not), should the need for this arise.
2023-05-17 16:38:56 +02:00
Iliya Katueshenock
f7388e3be5 Cleanup: Move BKE_node.h to C++
See: https://projects.blender.org/blender/blender/issues/103343

Changes:
1. Added `BKE_node.hh` file. New file includes old one.
2. Functions moved to new file. Redundant `(void)`, `struct` are removed.
3. All cpp includes replaced from `.h` on `.hh`.
4. Everything in `BKE_node.hh` is on `blender::bke` namespace.
5. All implementation functions moved in namespace.
6. Function names (`BKE_node_*`) changed to `blender::bke::node_*`.
7. `eNodeSizePreset` now is a class, with renamed items.

Pull Request: https://projects.blender.org/blender/blender/pulls/107790
2023-05-15 15:14:22 +02:00
Campbell Barton
169dd2a2b4 Use UTF8 copy function to ensure valid UTF8 output 2023-05-13 17:38:48 +10:00
Bastien Montagne
3b647faec8 Fix (unreported) three wrong next/prev pointers order in ListBase link structs.
There was even one case in BLI ListBase tests!

Order was opposite of the one expected by the BLI ListBase code... Not
sure how, but this did not cause any issue apparently? But would expect
it to at least affect the order in which items in the list would be
iterated.
2023-05-12 19:02:39 +02:00
Campbell Barton
3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
Campbell Barton
f665b73c89 RNA: replace BLI_strncpy with strcpy/memcpy when the size is known
Follow up on [0] handle remaining cases where BLI_strncpy was used
it RNA string get callbacks.

[0]: c891dbd162
2023-05-05 14:01:57 +10:00