Fix Blender 5.2 texture readback corruption - #67
Conversation
|
Thanks for tracking this down, and for flagging the Codex provenance up front. I verified the mechanism independently and tested on macOS. Your diagnosis is correct and the fix works. Confirmed on macOS / Blender 5.2 / NDI — clean output with the patch applied. That's worth calling out because this issue reads as Windows-only, and it isn't. Root causeBlender commit - r_strides[0] = GPU_texture_dataformat_size(format);
- for (int i = 1; i < shape_len; i++) {
- r_strides[i] = r_strides[i - 1] * shape[i - 1];
+ Py_ssize_t stride = GPU_texture_dataformat_size(format);
+ for (int i = shape_len; i-- > 0;) {
+ r_strides[i] = stride; stride *= shape[i];For shape
So numpy genuinely returned a transposed array on older Blender and It shears rather than crashing because Branch check: What's needed before mergeThe transpose is load-bearing on 5.1 and earlier, so removing it unconditionally trades the 5.2 bug for the same bug on every older version. The README claims support back to 4.x, and the affected surface is wider than this PR suggests: NDI on all platforms plus Spout on Windows. I have not tested 5.1 with the patch applied, so that regression is a prediction from the stride arithmetic rather than something I've observed. But the arithmetic is unambiguous and I'd want the guard in place regardless. Please gate the transpose, something like: image_array = np.asarray(texture.read(), dtype=np.uint8)
if not _C_ORDER_BUFFER:
image_array = image_array.transpose()
image_array = image_array.reshape(self.height, self.width, 4)Detecting it at runtime ( With that guard added, this is good to merge. Minor notes
Scoping out the Cycles black frame is the right call, that's capture architecture rather than buffer layout. Finally, for those in #63 who reported the patch not helping: the |
|
Addressed the pre-5.2 compatibility feedback in e7c03cc: Spout and NDI now transpose only when the runtime buffer is not C-order, the Blender stride-change comment is updated, and the dangling NDI comment is removed. Validation:
|
Summary
is_flippedbehaviorThis fixes the diagonal/corrupted output reported with Blender 5.2, where the buffer returned by
GPUTexture.read()already has the expected layout.Fixes #63.
Validation
python -m py_compile fbs/spout/SpoutServer.py fbs/ndi/NDIServer.pygit diff --checkCycles
We were unable to produce scene output from Cycles. The shared frame remained black except for viewport UI overlays, although Blender's own Cycles viewport rendered the scene. Camera movement updated the overlays, and changing exposure had no effect. This PR does not attempt to change the capture architecture or address that separate limitation.
Review note
This patch was produced using agentic coding with OpenAI Codex. Although the final code change is intentionally very small, it needs human review before merging.