It's safer to pass a type so that it can be checked if delete should be
used instead. Also changes a few void pointer casts to const_cast so that
if the data becomes typed it's an error.
Pull Request: https://projects.blender.org/blender/blender/pulls/137404
The goal here is to avoid having to cast to and from `ID` when getting the
evaluated or original ID using the depsgraph API, which is often verbose and not
type safe. To solve this, there are now `DEG_get_original` and
`DEG_get_evaluated` methods which are templated on the type and use a new
`is_ID_v` static type check to make sure it's only used with valid types.
This allows removing quite some verbosity on all the call sites. I also removed
`DEG_get_original_object`, because that does not have to be a special case
anymore.
Pull Request: https://projects.blender.org/blender/blender/pulls/137629
Some paths in Blender support the `//` prefix for blend-file relative
paths however this is not communicated anywhere.
Support declaring this with a new flag which can be applied to filepath
& dirpath typed properties.
This is used to:
- Show red-alert when "//" are used in paths which don't support a relative prefix.
- Show a warning in the tooltip that the relative suffix is used when unsupported.
- Python warns if this prefix is ever used in an assignment or
function argument.
Resolves#133456.
Ref !137060
While using constructors in Operator classes is _really_ not
recommended, BPY code was a bit too eager to overwrite existing errors
with its own generic messages.
Now only generate these exceptions if there is no other exception
already set.
When adding the assert I thought this wasn't happening on Linux
(since I'm unable to redo it locally).
However the builtbot hits this assert on Linux, causing tests to fail.
Resolves#135195
The code-path for coercing a dictionary to operator/gizmo properties
was being used RNA functions where it's not supported.
Raise a type exception instead of crashing.
Add `PointerRNA::reset()` and `PointerRNA::invalidate()` utils functions
(both simply reset the PointerRNA data to empty state).
Replace `RNA_POINTER_INVALIDATE` macro by `PointerRNA::invalidate()`.
Follow-up to !134393 and e55d478c64.
Reading & restoring RNA "writable" state wasn't working reliably when
Python was called from multiple threads.
- Resolve by acquiring the GIL before calling `pyrna_write_*` functions.
- Assert `pyrna_write_*` has the GIL to prevent this happening again.
- Move duplicate checks from bpy_props.cc into utility functions.
When registering a class, warn if it's base-classes or sub-classes
are already registered as this is bad practice.
Currently the check only runs when the `--debug-python` argument is used
to avoid overhead on startup.
`bpy.utils.unregister_class(bpy.types.Menu)` would remove `bl_rna`
type information from the menu (also Panels & other built-int types).
Prevent unregistering built-in types since this will only cause problems.
The general idea is to store an array of (type, data) pointers of all
PointerRNA ancestors of the current one.
This will help solving cases in our code where the owner (or sometimes
even the owner of the owner) of a random PointerRNA needs to be
accessed. Current solution mainly relies on linear search from the owner
ID, which is sub-optimal at best, and may not even be possible in case a
same data is shared between different owners.
This lead to refactoring quite a bit of existing PointerRNA creation code.
At a high level (i.e. expected usages outside of RNA internals):
* Add `RNA_pointer_create_with_parent` and
`RNA_pointer_create_id_subdata` to create RNA pointers with
ancestors info.
* `RNA_id_pointer_create` and `RNA_main_pointer_create` remain
unchanged, as they should never have ancestors currently.
* Add `RNA_pointer_create_from_ancestor` to re-create a RNA pointer
from the nth ancestor of another PointerRNA.
* Add basic python API to access this new ancestors data.
* Update internal RNA/bpy code to handle ancestors generation in most
common generic cases.
- The most verbose change here is for collection code, as the owner of the
collection property is now passed around, to allow collection items to get
a valid ancestors chain.
Internally:
* `PointerRNA` now has an array of `AncestorPointerRNA` data to store
the ancestors.
* `PointerRNA` now has constructors that take care of setting its data for
most usual cases, including handling of the ancestor array data.
* Pointer type refining has been fully factorized into a small utils,
`rna_pointer_refine`, that is now used from all code doing that operation.
* `rna_pointer_inherit_refine` has been replaced by
`rna_pointer_create_with_ancestors` as the core function taking care of
creating pointers with valid ancestors info.
- Its usage outside of `rna_access` has been essentially reduced to custom
collection lookup callbacks.
Implements #122431.
--------------
Some notes:
* The goal of this commit is _not_ to fully cover all cases creating
PointerRNA that should also store the ancestors' chain info. It only
tackles the most generic code paths (in bpyrna and RNA itself mainly).
The remaining 'missing cases' can be tackle later, as needs be.
* Performances seem to be only marginally affected currently.
* Currently `AncestorPointerRNA` only stores PointerRNA-like data.
This will help `StructPathFunc` callbacks to more efficiently generate
an RNA paths when calling e.g. `RNA_path_from_ID_to_property`, but will
not be enough info to build these paths without these callbacks. And some
cases may still remain fuzzy. We'd have to add thinks like a `PropertyRNA`
pointer, and for RNA collection ones, an index and string identifier, to store
a complete unambiguous 'RNA path' info. This is probably not needed, nor
worth the extra processing and memory footprint, for now.
Pull Request: https://projects.blender.org/blender/blender/pulls/122427
Caused by 59dc67974a
The behavior of `RNA_path_from_ID_to_property` /
`RNA_path_from_ID_to_property_index` is that it only gets the "prefix"
of the struct -- the one we are looking for, the one that is missing
here -- if we feed it the `newptr` since it calls
`RNA_path_from_ID_to_struct(ptr)` to get that prefix.
If we feed it the **ID** pointer it will be empty (makes sense it would
basically be "path from ID to ID"...we need it to be "path from ID to
constraint").
Pull Request: https://projects.blender.org/blender/blender/pulls/133977
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.
This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.
* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd
Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.
Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.
For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/
Pull Request: https://projects.blender.org/blender/blender/pulls/132608
Similar to 2fbf206491, but for integers (not strings). Essentially this
allows passing named integer values through UI abstractions in a clean
way.
I used 64 bit integers here, since space isn't an issue here, and it
fits common integer types (so we don't have to add APIs for multiple
integer types).
Planned to be used to fix#111463 (following commit).
Use StringRefNull for all function arguments and return types.
Not a StringRef but StringRefNull since there is still large
interaction with C api so null-termination usually necessary.
If string is expected to be not only empty but also a null then
optional is used. This change depends on #130935.
Pull Request: https://projects.blender.org/blender/blender/pulls/131204
When reporting "could not create instance of {class} to call callback
function {function}", put single quotes around the name of the function.
This will make it easier to understand that that word is actually a
function name, and not some verb in the sentence.
Before:
> RuntimeError: could not create instance of
> AMP_TIMELINE_TOOLS_OT_anim_lattice to call callback function execute
After:
> RuntimeError: could not create instance of
> AMP_TIMELINE_TOOLS_OT_anim_lattice to call callback function 'execute'
Pull Request: https://projects.blender.org/blender/blender/pulls/129780