Commit Graph

28064 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
Sean Kim
875f9abe9d Merge branch 'blender-v4.4-release' 2025-02-19 13:04:40 -08:00
Sean Kim
f1fca48a4f Fix #134292: Clone brush cannot access local blendfile images
With the brush assets project, brushes were moved from being local to
the working blendfile to being linked from asset libraries. This breaks
the Image Paint 'Clone' brush, as it has a brush property that links to
other Image datablocks.

To support this functionality, this commit adds the corresponding
properties into the `ImagePaintSettings` struct so that it is stored
locally with the images that will be used by the tool, inside the main
blendfile.

The source image property is shared with the 3D version of the 'Clone'
brush instead of adding a separate field to preserve old behavior.

Notably, this has the following limitations:
* If clone brush assets have been made and shared with external packs,
  they would not work out of the box with linked image assets.
* Despite these settings being stored on the scene, they are populated
  inside the tool window under "Brush Settings" which is potentially
  misleading. However, this is already the case for the 3D version of
  the brush, so further UI refinement will happen outside of this PR.
* Users will be unable to use separate images simultaneously for the
  Image editor and the 3D viewport, unlike in pre-4.3 versions. This
  can be adjusted in the future if it is a critical workflow.

Because the intended design and functionality of this tool is currently
questionable, this commit opts to make these changes instead of doing
further design to support both accessing data on the brush and on the
scene.

Pull Request: https://projects.blender.org/blender/blender/pulls/134474
2025-02-19 22:00:39 +01:00
Sean Kim
5cce8cc073 Merge branch 'blender-v4.4-release' 2025-02-19 12:59:30 -08:00
Sean Kim
af8da338a0 Fix #134770: Multires persistent base doesn't work randomly
The previous attempt to restore this behavior was in
0a2d5d5801

That commit introduced clearing the related `SculptSession` variables
when the paint BVH was freed to avoid bad behaviors seen in 4.2 and
prior. However, this solution is somewhat incorrect, as the prior state
of this data is not necessarily restored when the BVH is recreated,
unlike other temporary mapping data.

This results in the persistent base data being cleared occasionally with
no indication to the user that this is happening, causing the setting to
appear to be inactive.

To fix this, this commit makes a few changes:
* Removes clearing this data in the `BKE_sculptsession_free_pbvh`
  function.
* Initializes the displacement arrays to the same size as the position
  and normal array.
* Introduce new variables to track the saved multires grid size so
  that it is not deleted, only considered invalid when the topology
  changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/134780
2025-02-19 21:58:49 +01:00
Dalai Felinto
1584cd9aa5 Cleanup: Rename point cloud to pointcloud / POINT_CLOUD to POINTCLOUD
Though "Point Cloud" written as two words is technically correct and should be used in the UI, as one word it's typically easier to write and parse when reading. We had a mix of both before this patch, so better to unify this as well.

This commit also renames the editor/intern/ files to remove pointcloud_ prefix.
point_cloud was only preserved on the user facing strings:

* is_type_point_cloud
* use_new_point_cloud_type

Pull Request: https://projects.blender.org/blender/blender/pulls/134803
2025-02-19 17:11:08 +01:00
илья _
119fc054f8 Cleanup: BKE: Nodes: Pass-by-reference
Restriction of the nodes api to clearly define never-null function arguments.
Side effects: some assertions and null-check (with early return) were removed.
On the caller side is ensured to never derefer null to pass argument (mainly in RNA).
In addition, one pointer argument now actually a return type.

By-reference return types instead of pointers going to be separate kind of
change since also imply of cleaning up variables created from reference.

Also good future improvement would be to mark a copy-constructor as
explicit for DNA node types.

Pull Request: https://projects.blender.org/blender/blender/pulls/134627
2025-02-19 13:44:11 +01:00
Brecht Van Lommel
e166c25c0b Merge branch 'blender-v4.4-release' 2025-02-19 11:47:19 +01:00
Brecht Van Lommel
3004848372 Fix #134756: Internal text datablock filepath considered missing
When the text datablock was marked as external at one point and the
filepath was allocated, it would be considered missing.
2025-02-19 11:26:57 +01:00
Bastien Montagne
4ec5d600cd Refactor: Core: Make BKE_libblock_alloc_notest return ID pointer. 2025-02-19 10:55:05 +01:00
Brecht Van Lommel
6458458c07 Merge branch 'blender-v4.4-release' 2025-02-18 19:46:42 +01:00
Brecht Van Lommel
c650977534 Grease Pencil: Make brush asset pinned materials local
Keeping these as linked datablocks to the brush does not match the idea
that assets should generally be appended, and leads to some confusing
situations with linked materials on objects. Now use either a local
material with matching weak library reference or make a local copy if
it does not exist yet.

This also add weak library references to the materials in the 2D Animation
template, so they will be reused.

A problem is that weak library references include a full path to assets
blend files, including the Blender version for the essentials assets files.
This means weak library references do not work across platforms and
Blender versions.

Another known limitation is that if the (linked) Brush Asset material is
edited, and there is already a local copy of it, this local copy will
remain unchanged and will be used by future strokes as well.

Ref #131186

Pull Request: https://projects.blender.org/blender/blender/pulls/134226
2025-02-18 19:46:07 +01:00
Brecht Van Lommel
1602658461 Refactor: Simplify grease pencil brush material API surface
To make changes in the following commit more clear.

Pull Request: https://projects.blender.org/blender/blender/pulls/134226
2025-02-18 19:46:07 +01:00
Brecht Van Lommel
3af82d2ea0 Fix: Preserving linked editable asset datablock fails with embedded ID
This is needed to make materials work with this system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134226
2025-02-18 19:46:07 +01:00
Hans Goudey
b520302420 Merge branch 'blender-v4.4-release' 2025-02-18 11:32:47 -05:00
Hans Goudey
4b6a212986 Cleanup: Formatting 2025-02-18 11:30:17 -05:00
Hans Goudey
2555f68267 Merge branch 'blender-v4.4-release' 2025-02-18 10:55:49 -05:00
Hans Goudey
d0a89a0950 Fix #134707: Dynamic paint brush object movement ignored
Caused by bcfe4c34da.

The code was missing a dirty tag for the positions.
2025-02-18 10:54:41 -05:00
Miguel Pozo
f5d56a3124 GPU: Add --profile-gpu
Add a `--profile-gpu` launch argument.

When set, it generates a profile in the Trace Event Format with CPU and
GPU metrics based on GPU debug scopes.
https://profilerpedia.markhansen.co.nz/formats/trace-event-format/

The profiles are best viewed at https://ui.perfetto.dev/

Notes:
- The profiler captures everything form app start to exit.
- Being JSON based the profiles can become relatively large, but they
  compress very well.
- Only OpenGL profiling is supported for now, but the report formatting
  code can be shared across backends.

Pull Request: https://projects.blender.org/blender/blender/pulls/133557
2025-02-18 15:36:50 +01:00
Julian Eisel
20ec789889 Merge branch 'blender-v4.4-release' 2025-02-18 14:15:28 +01:00
Julian Eisel
fa4026f2bf Revert "Fix #130372: Implements memory of the previous state of eSpace_Types."
This reverts commit afec64739a.

The commit introduces a regression where opening the Asset Browser opens
the File Browser instead, same for other editor sub-types, see
blender/blender#134630.
blender/blender!134642 proposes a different solution and reverts this,
which I prefer too. Better to the revert separately from trying a
different fix for the initial bug, makes reviewing easier too.
2025-02-18 14:09:42 +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
Hans Goudey
59fad71a47 Fix: Copy caches in point cloud "nomain to main" function
Previously the bounds and BVH caches were incorrectly not updated.
2025-02-17 18:39:47 -05:00
Dalai Felinto
ec6383de96 Point Cloud: Delete operator
Note: The point cloud bounding box is not being updated once the points are deleted.

This is a known issue with BKE_pointcloud_nomain_to_pointcloud and Hans is looking into it.

Code inspired/built based on the Delete Geometry node.

Pull Request: https://projects.blender.org/blender/blender/pulls/134622
2025-02-18 00:28:14 +01:00
Hans Goudey
947658d1b2 Refactor: Simplify CustomData functions by requiring ImplicitSharingInfo
Previously we generally expected CustomData layers to have implicit
sharing info, but we didn't require it. This PR clarifies that we do
require layers with non-null data to have implicit sharing info. This
generally makes code simpler because we don't have to have a separate
code path for non-shared layers. For example, it makes the "totelem"
arguments for layer freeing functions unnecessary, since shared data
knows how to free itself. Those arguments are removed in this PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/134578
2025-02-17 19:44:54 +01:00
Hans Goudey
901b18d17b Point Cloud: Add cached full points BVH tree
Instead of rebuilding the BVH tree every time it's requested.
2025-02-17 12:11:06 -05:00
Jacques Lucke
cb96dc34fa Merge branch 'blender-v4.4-release' 2025-02-17 12:38:50 +01:00
Jacques Lucke
78b5c47c46 Fix #134669: crash because of dangling socket declaration pointer 2025-02-17 12:37:23 +01:00
Hans Goudey
aff784aa14 Point Cloud: Implement "Affect only Origins" object transform option
Basically the same code as the curves support in this area.
2025-02-16 20:48:46 -05:00
Hans Goudey
c1c67c918e Refactor: Various C++ cleanups to object data transform
Make `XFormObjectData` a real virtual struct instead of using
C style over-allocation. Use C++ arrays and math types.
2025-02-16 20:31:09 -05:00
Campbell Barton
c97a2e86a9 Merge branch 'blender-v4.4-release' 2025-02-16 21:00:42 +11:00
Campbell Barton
665b4dfbad Fix IDProperty comparison warning in debug mode
The warning to check if two numbers are nearly equal when comparing
floats didn't take negative numbers into account, causing -1.0 & 0.0
for e.g. to be considered not equal but close.
This also resolves a divide by zero.
2025-02-16 20:56:07 +11:00
Hans Goudey
4727dfd627 Cleanup: Remove unnecessary const qualifiers in function declarations 2025-02-14 14:32:57 -05:00
Hans Goudey
7c3a3669b6 Cleanup: Remove unused CustomData functions 2025-02-14 12:45:39 -05:00
Falk David
e1ab205148 Merge branch 'blender-v4.4-release' 2025-02-14 18:33:24 +01:00
Jacques Lucke
bb715caf94 Fix #134100: hair curves disappear when adding new curves without radius interpolation
The issue is that the existing curves did not have an explicitly set radius.
When adding new curves with an explicit radius, the radius of the old curves was
initialized to 0 and thus becoming invisible. This patch changes it so that all
the existing curves do get a default radius. The `radius_for_write` methods is
currently only used in places that overwrite the entire array, so adding the
default there shouldn't affect anything unintentionally.

Pull Request: https://projects.blender.org/blender/blender/pulls/134445
2025-02-14 17:41:59 +01:00
Bastien Montagne
c43a583370 Merge branch 'blender-v4.4-release' 2025-02-14 17:21:17 +01:00
Bastien Montagne
bbebf72a33 Cleanup: Add explicit defaults to MEM_new-allocated structs with no constructors.
While not strictly needed (currently!), relying on C++ 'default
initialization' is fragile and unreliable.
2025-02-14 17:07:23 +01:00
Falk David
2cc6f7bbb5 Fix #133339: Grease Pencil: Ensure span attribute writers are valid
When calling the `lookup_or_add` functions on `MutableAttributeAccessor`
we need to make sure that the writer is actually created and the call
did not fail.

This fixes many of the instances where we would use an unchecked
attribute writer and potentially crash.

Pull Request: https://projects.blender.org/blender/blender/pulls/134413
2025-02-14 15:54:20 +01:00
Sybren A. Stüvel
1feca529d8 Merge remote-tracking branch 'origin/blender-v4.4-release' 2025-02-14 14:00:16 +01:00
Sybren A. Stüvel
62c21a0800 Fix: NLA Track Solo flag handling, in depsgraph and F-Curve iteration
This fixes the (unreported) issue where solo'ing an NLA track would only
play back animation when _any_ of the tracks were unmuted.

Some code considered a track to be muted when its `NLATRACK_MUTED` flag
was set regardless of the `NLATRACK_SOLO` flag, whereas other code did
consider the `NLATRACK_SOLO` flag.

Now all the code is consistent with what actual animation evaluation is
doing.

Pull Request: https://projects.blender.org/blender/blender/pulls/134500
2025-02-14 13:55:44 +01:00
Bastien Montagne
aaef10e99e Merge branch 'blender-v4.4-release' 2025-02-13 19:31:28 +01:00
Bastien Montagne
455d419f1e Fix (unreported) invalid C-style allocation of non-trivial C++ data. 2025-02-13 19:24:17 +01:00
Hans Goudey
8fed30aff2 Fix #134485: Missing depsgraph tag when assigning material
Caused by 81a63153d0.

Previously this was done by BKE_objects_materials_sync_length_all.
Now that function only adds a tag when it actually does something.
2025-02-13 13:16:57 -05:00
Brecht Van Lommel
4786fbe774 Refactor: Remove extern "C" from most headers
The only remaining code in source/blender that must be compiled as C
is now datatoc generated code and the DNA defaults that use designated
initializers.

Pull Request: https://projects.blender.org/blender/blender/pulls/134469
2025-02-13 18:58:08 +01:00
Harley Acheson
83c94c6537 Merge branch 'blender-v4.4-release' 2025-02-13 09:46:08 -08:00
Fabricio Luis
afec64739a Fix #130372: Implements memory of the previous state of eSpace_Types.
This implements the memorization of the previous state of a space's
subtype for those that have multiple modes. Introduces an optional
space_subtype_prev_get callback, implemented for SPACE_ACTION,
SPACE_FILE, SPACE_GRAPH, SPACE_IMAGE and SPACE_NODE. This means we
can always return to the previous mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/133846
2025-02-13 18:45:00 +01:00
Bastien Montagne
48636fcab4 Merge branch 'blender-v4.4-release' 2025-02-13 18:42:16 +01:00
Bastien Montagne
e30b78fec4 Fix (unreported) invalid usage of C-style allocation for non-trivial C++ data. 2025-02-13 18:41:41 +01:00