Commit Graph

7035 Commits

Author SHA1 Message Date
Jacques Lucke
46fc5cb2cf Python: flush stdout and stderr after running Python script
When debugging with gdb in vscode, the stuff I print when executing a script in
the text editor does not show up in the terminal. It does work when I flush
explicitly though using `print(..., flush=True)`. This is quite annoying.

The solution is to always flush `stdout` and `stderr` automatically when running
a script. This is done using the CPython API, as just using
`fflush(stdout/stderr)` did not solve the issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/136632
2025-04-01 12:41:38 +02:00
Campbell Barton
3e496a5dfe Cleanup: add missing doxygen file headers 2025-04-01 12:35:01 +11:00
Campbell Barton
7ae020ecd1 Cleanup: use our utility function to create a PyUnicode from a std:str 2025-04-01 12:33:56 +11:00
Campbell Barton
e3d6051181 Cleanup: suppress cast-function-type warnings for CLANG
Extend the existing GCC pragma's and add the warning suppression
for Cycles & Freestyle.
2025-04-01 12:06:03 +11:00
Campbell Barton
ccbf8c0544 Cleanup: resolve unknown pragma warning for CLANG 2025-04-01 12:05:25 +11:00
Jeroen Bakker
5a5471b622 Python: Add GPUShaderCreateInfo.depth_write method
Setting depth_write option of ShaderCreateInfo isn't available in
python GPU module. This PR adds support of it.

References #136732

Pull Request: https://projects.blender.org/blender/blender/pulls/136752
2025-03-31 12:37:56 +02:00
Jacques Lucke
29fddf4710 Python: Geometry: create GeometrySet wrapper for Python
In Geometry Nodes a geometry is represented by a `GeometrySet`. This is a
container that can contain one geometry of each of the supported types (mesh,
curves, volume, grease pencil, pointcloud, instances). It's possible for a
`GeometrySet` to contain e.g. a mesh and a point cloud.

This patch creates a Python  wrapper for the built-in `GeometrySet`. For now,
it's main purpose is to consume the complete evaluated geometry of an object
without having to go through complex hoops via `depsgraph.object_instances`. It
also also allows retrieving instances that have been created with legacy
instancing systems such as dupli-verts or particles.

In the future, the `GeometrySet` API could also be used for more kinds of
geometry processing from Python, similar to how we use `GeometrySet` internally
as generic geometry storage.

Since we can't really have constness guarantees in Python currently, it's
enforced that the `GeometrySet` wrapper always has its own copy of each geometry
type (so e.g. it does not share a `Mesh` data-block pointer with any other place
in Blender). Without the copy, changes to the mesh in the geometry set would
also affect the evaluated geometry that Blender sees. The copy has a small cost,
but typically the overhead should be low, because attributes and other run-time
data can still be shared. This should be entirely thread-safe, assuming that no
code modifies implicitly shared data, which is forbidden. For historic reasons
there are still cases like #132423 where this assumption does not hold in all
cases. Those cases should be fixed. To my knowledge, this patch does not
introduce any new such issues or makes existing issues worse.

Pull Request: https://projects.blender.org/blender/blender/pulls/135318
2025-03-28 22:40:01 +01:00
Campbell Barton
38d9d971e5 WM: add a "Hyper" capability flag
Avoids the need to check against ghost backends.
2025-03-28 13:46:39 +11:00
Campbell Barton
12e17e2477 Cleanup: use const arguments, variables 2025-03-28 00:59:11 +00:00
Brecht Van Lommel
a02e0fa147 Refactor: Improve image buffer save/load function names and arguments 2025-03-27 22:07:51 +01:00
Andrej730
224b8bb116 PyDoc: add node classes to register_class doc-string
Ref: !136375
2025-03-26 16:33:34 +11:00
Campbell Barton
6960d05df8 Fix: exception showing touch-pad preferences
Regression in [0] returned null without an exception set.

[0]: d9f38fca5f
2025-03-26 15:34:07 +11:00
Bastien Montagne
14913a447c Fix #136294: Blender 4.4 is discarding exceptions occurred in operator's constructor
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.
2025-03-21 11:29:59 +01:00
Campbell Barton
e1f91c2dba Cleanup: replace int with wmOperatorStatus, consistent naming
- Manually check over all direct calls to operator callbacks
  ensuring the result isn't assigned to an int.
- OPERATOR_RETVAL_CHECK() now fails unless a wmOperatorStatus is used.
- Check the return values of direct calls to callbacks.
- Remove invalid check for the return value of rna_operator_check_cb.
- Use the variable name `retval` as it's most widely used.
- Move the assignment of `retval` out of the `if` statement in
  sculpt/paint operators because it prevents assigning the result
  `const` variable.
2025-03-21 00:13:30 +00:00
Campbell Barton
2659ec12f5 Cleanup: replace int with wmOperatorStatus
Follow up to adding wmOperatorStatus, these cases were missed as they
didn't cause compiler warnings.
2025-03-21 08:34:21 +11:00
Brecht Van Lommel
9526fe9993 Refactor: Add BKE_mesh_new_from_object argument to ignore subdivision
Pull Request: https://projects.blender.org/blender/blender/pulls/135895
2025-03-19 14:08:37 +01:00
Campbell Barton
c3e5a35ecd PyAPI: add blf.bind_imbuf(..) context manager
Add support for using BLF to draw into an ImBuf image buffer.
Once the imbuf context has been set, draw calls for that font_id will draw into the image.

This works by binding an imbuf to BLF which is then used as the target when drawing.
```
with blf.bind_imbuf(font_id, imbuf):
    blf.draw_buffer(font_id, text)
```
See the example in the Python API documentation for reference.

The following BLF API's have been added to support a Python context manager.

- `BLF_buffer_state_push`.
- `BLF_buffer_state_pop`
- `BLF_buffer_state_free`

Ref !135772
2025-03-15 11:00:51 +11:00
Campbell Barton
78c3f6a1ee Cleanup: adjust order of terms for BMesh UV map function calls
Order more generic terms first for better ordering, more useful
completion.
2025-03-13 15:23:46 +11:00
Campbell Barton
6ef7dae8ef Cleanup: spelling in comments (make check_spelling_*) 2025-03-13 13:41:17 +11:00
Bastien Montagne
bb89c89e7f Cleanup: python: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

MEM_[cm]allocN<T> templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use MEM_new (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/135852
2025-03-12 11:21:53 +01:00
Campbell Barton
729b317061 Merge branch 'blender-v4.4-release' 2025-03-11 16:22:55 +11:00
Campbell Barton
90e47e6bc9 Fix error saving a new imbuf from the Python API
Correct the argument for the number of planes.
2025-03-11 16:18:36 +11:00
Campbell Barton
9b9ed06467 Merge branch 'blender-v4.4-release' 2025-03-06 10:19:49 +11:00
Campbell Barton
2d705f90c2 PyAPI: disable assertion when building Blender as a Python module
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
2025-03-06 10:17:37 +11:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
Campbell Barton
c7cde524fb Revert "PyAPI: document never none pointer/collection properties"
This reverts commit
48abc7aabc &
62599317dd.

Revert !126755 as it was only meant to impact document generation
but it infact made functional changes, see: !135352.
2025-03-04 22:20:40 +11:00
Aras Pranckevicius
cc2c6692c0 Cleanup: Name more IMB things as "byte" or "float" instead of "rect" and "rectFloat"
- IB_rect -> IB_byte_data
- IB_rectfloat -> IB_float_data
- Rename some functions:
	- IMB_get_rect_len -> IMB_get_pixel_count
	- IMB_rect_from_float -> IMB_byte_from_float
	- IMB_float_from_rect_ex -> IMB_float_from_byte_ex
	- IMB_float_from_rect -> IMB_float_from_byte
	- imb_addrectImBuf -> IMB_alloc_byte_pixels
	- imb_freerectImBuf -> IMB_free_byte_pixels
	- imb_addrectfloatImBuf -> IMB_alloc_float_pixels
	- imb_freerectfloatImBuf -> IMB_free_float_pixels
	- imb_freemipmapImBuf -> IMB_free_mipmaps
	- imb_freerectImbuf_all -> IMB_free_all_data
- Remove IB_multiview (not used at all)
- Remove obsolete "module" comments in public IMB headers

Pull Request: https://projects.blender.org/blender/blender/pulls/135348
2025-03-03 17:11:45 +01:00
Campbell Barton
8a78a6dc61 Merge branch 'blender-v4.4-release' 2025-02-28 17:09:51 +11:00
Campbell Barton
bba5b88b29 Fix #135245: Crash passing a dict for OperatorProperties to RNA funcs
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.
2025-02-28 16:59:53 +11:00
Philipp Oeser
51f0758f61 Merge branch 'blender-v4.4-release' 2025-02-26 14:14:36 +01:00
Philipp Oeser
d2ecf66492 Fix #120697: better error for BVHTree.FromObject()
When called on an object that you cannot get a mesh from (e.g. Empties),
you would run into an unhelpful "SystemError: <built-in method
FromObject of type object at ...> returned NULL without setting an
exception"

Now be more specific in the error message.

Pull Request: https://projects.blender.org/blender/blender/pulls/135162
2025-02-26 14:14:14 +01:00
Campbell Barton
62599317dd Fix #135009: Python: Can't Set PointerProperty to None
Correct own error applying !126755.
2025-02-25 11:04:48 +11:00
Bastien Montagne
6b0ad2e16b Refactor: Replace RNA_POINTER_INVALIDATE RNA/BPY macro usages.
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.
2025-02-18 12:43:43 +01:00
Andrej730
48abc7aabc PyAPI: document never none pointer/collection properties
Set never null for pointer props automatically during RNA generation.

Ref: !126755
2025-02-18 11:27:19 +11:00
Jacques Lucke
cb96dc34fa Merge branch 'blender-v4.4-release' 2025-02-17 12:38:50 +01:00
Andrej730
b9bbf48841 Fix: PyDocs typing issue with lists
Fixed use of lists using multiple arguments - `list` only
support a single argument.

Noticed working with fake-bpy-module - providing multiple
arguments to `list` resulted in typing error (e.g. "Too many type
arguments provided for "list"; expected 1 but received 2").

Pull Request: https://projects.blender.org/blender/blender/pulls/134663
2025-02-17 10:58:11 +01:00
Campbell Barton
9b0df7c60a Merge branch 'blender-v4.4-release' 2025-02-16 18:32:17 +11:00
Campbell Barton
c80980d10b Fix #125376: Standalone bpy module can crash on exit 2025-02-16 18:27:02 +11: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
Campbell Barton
8e8364f645 Merge branch 'blender-v4.4-release' 2025-02-13 20:48:23 +11:00
Campbell Barton
77eed053b2 Unbreak build WITH_PYTHON=ON & Python <= v3.12 2025-02-13 20:45:26 +11:00
Campbell Barton
e52f85b33c Cleanup: move Python's GIL ensure/release to the function start/end
Avoid errors accessing state without the GIL (#127767) by moving
GIL ensure/release to the star/end of the function body.
2025-02-13 17:56:42 +11:00
Campbell Barton
886e40f136 Merge branch 'blender-v4.4-release' 2025-02-13 17:47:20 +11:00
Campbell Barton
39e23e29fe Cleanup: remove unnecessary call to PyGILState_Ensure
There is no need to aquire the GIL for Python methods.
2025-02-13 17:09:10 +11:00
Campbell Barton
516b39ad22 Merge branch 'blender-v4.4-release' 2025-02-13 16:57:40 +11:00
Campbell Barton
9222f157cb Fix #127767: bpy.app.handlers could run in a read-only state
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.
2025-02-13 16:53:27 +11:00
Campbell Barton
640e70b6e8 Cleanup: various non-functional changes for C++ 2025-02-13 13:33:09 +11:00
Campbell Barton
e569417798 PyAPI: check registered classes don't depend on registered classes
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.
2025-02-13 13:04:50 +11:00
Campbell Barton
d0ac35eff4 Cleanup: add doxy-sections to bpy_rna.cc 2025-02-13 13:04:50 +11:00
Campbell Barton
c5a65ad9ed Merge branch 'blender-v4.4-release' 2025-02-13 12:01:00 +11:00