Commit Graph

68 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
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +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
Hans Goudey
4de00c1544 Cleanup: Move more ARegion runtime data out of DNA 2024-12-06 09:44:31 -05:00
Hans Goudey
d9c7c90e45 Fix #131494: Editor merging can crash Blender
Missing copied runtime data in 129a2aa0f4.
2024-12-06 09:23:35 -05:00
Hans Goudey
ef68097161 Fix #130826: Property search crash after recent region runtime cleanup 2024-11-24 13:37:59 -05:00
Hans Goudey
66a476455b Cleanup: Improve variable name for copied region 2024-11-24 13:37:59 -05:00
Hans Goudey
2b20871216 Cleanup: Move region UI block name map from GHash to Map 2024-11-21 14:04:34 -05:00
Hans Goudey
129a2aa0f4 Refactor: Move region runtime data out of DNA
Pull Request: https://projects.blender.org/blender/blender/pulls/130303
2024-11-21 19:34:53 +01:00
Julian Eisel
f0db870822 UI: Support persistent view state, write tree-view height to files
Adds support for saving some view state persistently and uses this to keep the
height of a tree-view, even as the region containing it is hidden, or the file
re-loaded.

Fixes #129058.

Basically the design is to have state stored in the region, so it can be saved
to files. Views types (tree-view, grid-view, etc) can decide themselves if they
have state to be preserved, and what state that is. If a view wants to preserve
state, it's stored in a list inside the region, identified by the view's idname.

Limitation is that multiple instances of the same view would share these bits of
state, in practice I don't think that's ever an issue.

More state can be added to be preserved as needed. Since different kinds of
views may require different state, I was thinking we could add ID properties to
`uiViewState` even, making it much more dynamic.

Pull Request: https://projects.blender.org/blender/blender/pulls/130292
2024-11-18 18:19:48 +01:00
Hans Goudey
091c175c5c Refactor: Move region runtime to separate C++ runtime struct
This allows using C++ types in the region runtime data, which will
make it easier to move the remaining runtime data out of the
`ARegion` DNA type and improve code readability in these areas.

Pull Request: https://projects.blender.org/blender/blender/pulls/130196
2024-11-15 02:00:11 +01:00
Bastien Montagne
320c77b963 Fix #123769: Assert when saving a file with deleted workspaces.
Delete sceens when their workspace is deleted.

Also remove `IDTYPE_FLAGS_NEVER_UNUSED` tag from bScreen ID type, there
is no more point to keep these IDs around if they are not used, there
are supposed to be mere sub-data of the Workspaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/129975
2024-11-07 18:22:21 +01:00
Julian Eisel
a641001207 Fix: UI previews don't refresh outside of properties editor
The preview template (`UILayout.template_preview()`) to display previews
for materials, textures or similar would only work correctly in the
Properties editor. This had explicit logic to trigger rerendering on
changes. When displaying such previews elsewhere (e.g. in the 3D View
sidebar), the only way to have changes reflected would be by resizing
the preview.

This fix makes sure such previews are tagged as dirty and refreshed on
changes to the underlying ID. We do this the same way as tagging the ID
previews as dirty, through a function called by the dependency graph for
such updates.

Pull Request: https://projects.blender.org/blender/blender/pulls/129641
2024-11-01 15:25:24 +01:00
Bastien Montagne
22477956e2 Refactor: Move BPY main/public extern headers to proper C++ ones.
Pull Request: https://projects.blender.org/blender/blender/pulls/128081
2024-09-25 18:04:33 +02:00
Campbell Barton
22397ad819 Fix #128012: disabling "Load UI" makes nodes unselectable
Resolve regression in [0] which caused the tool not to refresh
when loading a file without it's UI.

[0]: 83fe5712ab
2024-09-24 17:41:53 +10:00
Campbell Barton
9b39b4c91c Cleanup: use const pointers/references 2024-09-15 23:14:09 +10:00
Bastien Montagne
733ed5dc83 Refactor: Move some UI-related allocations to use C++ new/delete.
Mainly changes some UI-internal structs allocation, and the Panel
runtime custom data storage.

These changes from C-style alloc/free to C++ new/delete are a step
towards making PointerRNA non-trivial (part of #122431).

Pull Request: https://projects.blender.org/blender/blender/pulls/126698
2024-08-27 15:35:18 +02:00
Philipp Oeser
f53b6b89f8 Fix: Editor related RNA paths incomplete/wrong
The RNA path that is generated for Editor properties were mostly
incomplete (e.g. the viewport overlay settings).
- in python tooltips
- from the `Copy (Full) Data Path` operator
- python methods `path_from_id`, `path_resolve` returned incomplete paths

Since a space (editor) is ultimately owned by the screen, we now add the
missing "areas[x].spaces[x]" subpath to any editor.
Nested structs (like the viewport overlay) also need to include this
subpath.

Some editor related structs are not tied to a single space though (and
these cases are therefor not resolved yet):
- Dopesheet is referenced from SpaceGraph, SpaceAction and SpaceNla
- View3DShading is referenced from SpaceView3D but render engines as
well
- FileSelectParams / FileAssetSelectParams / FileAssetSelectIDFilter
need more investigation

NOTE: in case of the VSE, to make this work this also changes the
overlays to be tied to SpaceSeq (the only editor using them)
NOTE: since the above is now in place, adding VSE overlay props to Quick
favourites is now made possible as well (was a leftover from !116604)

Fixes #124527, #113489

Pull Request: https://projects.blender.org/blender/blender/pulls/125365
2024-08-05 16:54:34 +02:00
Bastien Montagne
6435bcbdef Refactor: Fix for proper usage of BLO API calls in some trivial cases.
All of these changes should be trivial, like using `string` read/write
code for strings, and a convert a few usages of 'raw data' read/write
calls to the 'struct' ones.

No behavioral changes expected here.
2024-07-31 18:30:50 +02:00
Bastien Montagne
5270d72426 Fix (unreported) yet another MEM_new/MEM_freeN mismatch... 2024-07-08 13:54:15 +02:00
Bastien Montagne
6426de4489 Core: IDManagement: Refactor how 'never unused' IDs are defined.
A few ID types are considered as 'never unused' in Blender (UI related
ones, the Libraries and the Scenes). Local IDs of this type are always
considered as used, even if no other ID links to them.

This was previously fairly weekly defined and implemented (mainly in the
writefile code and the 'tag unused' libquery functions).

This commit formalize this characteristic of ID types by adding a new
`IDTYPE_FLAGS_NEVER_UNUSED` flag, and using this in the few places in
the code that handle unused IDs.
2024-05-24 17:43:22 +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
Brecht Van Lommel
29c3997c28 Fix: Crash reading some particular old blend files 2024-04-23 19:52:20 +02:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Campbell Barton
e33f5e36ac Cleanup: spacing around C-style comment blocks 2024-03-09 23:40:57 +11:00
Bastien Montagne
df0efda0d6 Refactor: IDTypeInfo: Add info about 'potentially used IDTypes'.
This data was 'hidden' away in a util in
`lib_query.cc`, which made it hard to discover and keep up-to-date.

However, as shown by e.g. #108407, critical low-level features in ID
management code, such as remapping, now rely on this information being
valid.

Also simplify `BKE_library_id_can_use_filter_id` and
`BKE_library_id_can_use_idtype` to make them more generic, relying on
IDTypeInfo to retrieve IDtype-specific info.

No behavioral changes expected here.
2024-02-15 19:45:10 +01:00
Campbell Barton
9e4129feeb Cleanup: unused includes in source/blender/blenkernel
Remove 397 includes.
2024-02-13 11:32:38 +11: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
cfb4e5a25d Cleanup: Store asset shelf types in vector of unique_ptr
This avoids the need for manual memory management/raw pointers,
improves const correctness, improves type safety, simplifies iteration,
and simplifies the process of registering a new asset shelf type.

Pull Request: https://projects.blender.org/blender/blender/pulls/117770
2024-02-05 16:23:57 +01:00
Hans Goudey
f78d3a807a Cleanup: Store space types in vector of unique_ptr
- Use unique_ptr instead of raw pointers
- Use Vector instead of a linked list
- Use a destructor instead of a free function
- Remove the space type template-- it's much clearer to copy functional code

Pull Request: https://projects.blender.org/blender/blender/pulls/117766
2024-02-02 20:59:20 +01:00
Hans Goudey
fb0d6198c0 Cleanup: Move remaining asset editors code to C++ namespace 2024-01-26 18:43:13 -05:00
Hans Goudey
0e6aad4742 Cleanup: Remove remaining asset editor headers to C++ 2024-01-26 18:15:40 -05:00
Bastien Montagne
af5731ce03 Cleanup: Move BKE_idtype.h to Cpp header BKE_idtype.hh 2024-01-20 19:17:36 +01:00
Bastien Montagne
03c1cc4310 Cleanup: Move BKE_lib_query header to Cpp era. 2024-01-18 12:21:19 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Jacques Lucke
8896446f7e Python: add Python API for layout panels
This adds a Python API for layout panels that have been introduced in #113584.
Two new methods on `UILayout` are added:
* `.panel(idname, text="...", default_closed=False) -> Optional[UILayout]`
* `.panel_prop(owner, prop_name, text="...") -> Optional[UILayout]`

Both create a panel and return `None` if the panel is collapsed. The difference lies
in how the open-close-state is stored. The first method internally manages the
open-close-state based on the provided identifier. The second one allows for
providing a boolean property that stores whether the panel is open. This is useful
when creating a dynamic of panels and when it is difficult to create a unique idname.

For the `.panel(...)` method, a new internal map on `Panel` is created which keeps
track of all the panel states based on the idname. Currently, there is no mechanism
for freeing any elements once they have been added to the map. This is unlikely to
cause a problem anytime soon, but we might need some kind of garbage collection
in the future.

```python
import bpy
from bpy.props import BoolProperty

class LayoutDemoPanel(bpy.types.Panel):
    bl_label = "Layout Panel Demo"
    bl_idname = "SCENE_PT_layout_panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        layout.label(text="Before")

        if panel := layout.panel("my_panel_id", text="Hello World", default_closed=False):
            panel.label(text="Success")

        if panel := layout.panel_prop(scene, "show_demo_panel", text="My Panel"):
            panel.prop(scene, "frame_start")
            panel.prop(scene, "frame_end")

        layout.label(text="After")

bpy.utils.register_class(LayoutDemoPanel)
bpy.types.Scene.show_demo_panel = BoolProperty(default=False)
```

Pull Request: https://projects.blender.org/blender/blender/pulls/116949
2024-01-11 19:08:45 +01:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Bastien Montagne
3aa5644751 Merge branch 'blender-v4.0-release' 2023-10-19 21:42:26 +02:00
Damien Picard
e3fc935349 I18n: disambiguate and extract a few messages
Extract:
- Sculpt filter types from the Sculpt menu. Some of these types use a
  custom label, different  from those defined in the operator RNA,
  which was never extracted.
- "Today" and "Yesterday" from the file browser modification date.
- All name_plural from IDs, as these are used in the UI to list which
  data block is to be removed, when calling outliner.orphans_purge.

Disambiguate:
- "Area", meaning the measurement of a surface as opposed to a place.

Some messages reported by Satoshi Yamasaki in #43295.

Pull Request: https://projects.blender.org/blender/blender/pulls/113912
2023-10-19 21:39:58 +02:00
Jacques Lucke
c52582e3fe Fix: properties search crash
The issue was that the panel run-time pointer was overwritten by
the shallow copy.
2023-10-11 16:44:54 +02:00
Jacques Lucke
449ded0258 Fix #113545: crash when trying to create panel with unknown type
Caused by 6a6dd392e2.
2023-10-11 16:08:17 +02:00
Jacques Lucke
7a8600f967 Cleanup: remove accidentally committed asserts
I wanted to remove those before committing 6a6dd392e2.
2023-10-11 16:08:17 +02:00
Jacques Lucke
6a6dd392e2 Fix: copying panels in regions did not handle runtime data
Caused by 663aa353.
2023-10-11 12:48:40 +02:00
Jacques Lucke
1d516bba1e Cleanup: use C++ struct for panel runtime data 2023-10-11 11:52:46 +02:00
Jacques Lucke
663aa3538d UI: allocate panel runtime data separately
This results in better separation for what is stored in .blend files and what is not.
Also allows us to potentially use C++ in panel run-time data.

Pull Request: https://projects.blender.org/blender/blender/pulls/113502
2023-10-10 18:17:31 +02:00
Hans Goudey
916d4c9d9b Cleanup: Move BKE_screen.h to C++
See #103343
2023-09-25 17:53:11 -04:00
Julian Eisel
0519e8d711 UI: Remove panel name size limit for complex character languages
The previous limit of 63 bytes for the panel name was an issue for
languages where characters use multiple bytes. The UI would show panel
names truncated that had reasonably long/short names.

It's easy to support dynamically sized strings here, so do that instead
of using fixed size buffers.

Fixes #111927.

Pull Request: https://projects.blender.org/blender/blender/pulls/111979
2023-09-12 14:47:46 +02:00
Campbell Barton
52c4051d13 Cleanup: use doxy sections 2023-09-08 23:09:51 +10:00
Julian Eisel
ba03948dd2 Cleanup: Move BKE preview image code to separate file
Previously, BKE level preview image code was in `BKE_icons.h` and `icons.hh`.
While these types are related, I always found this quite hard to navigate since
preview image stuff was just in the middle of icon functions. Plus, people
don't expect preview image functions in icon files, the relationship is not
obvious.

Instead, use focused files that make it easy to quickly navigate them
and see what they are dealing with.

Pull Request: https://projects.blender.org/blender/blender/pulls/111709
2023-09-04 18:02:16 +02:00
Campbell Barton
23e8ffd72d Cleanup: various non-functional C++ changes, format 2023-09-01 11:19:44 +10:00