Skip to content

Fix rand_vec_spread_deg directions, large GL reads, and pixel test helpers - #2945

Merged
pvcraven merged 1 commit into
developmentfrom
fix/math-and-gl-reads
Oct 8, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/math-and-gl-reads

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Three small fixes found while triaging issues.

rand_vec_spread_deg points in random directions (fixes #2648)

arcade.math.rand_vec_spread_deg(angle, half_angle_spread, length) passed the angle in degrees to Vec2.from_polar, which takes radians. So rand_vec_spread_deg(90, 5, 1) gave directions like -26°, 110° and -150°. Two emitters in the particle_systems example use it and sprayed everywhere. It now converts the angle to radians, and the docstring says both angles are in degrees.

Not changed: the same example calls rand_vec_magnitude(45, ...), which takes radians, so those two emitters fire at about 58° instead of 45°. They still fire in one fixed direction as described, so I left them alone.

Reads of 2 GB or more fail on Windows (fixes #2836)

Texture, texture array, framebuffer and buffer reads used ctypes.string_at(ptr, size). Its size is a C long, which is 32 bits on Windows. I confirmed it with a 2 GB ctypes array:

  • string_at raised SystemError: Negative size passed to PyBytes_FromStringAndSize.
  • bytes(buffer) read all of it in 0.65 s.

These reads now copy with bytes(). The buffer read, which maps a pointer, casts it to a ctypes array of the right size first. Linux has a 64-bit long, so it wasn't affected.

Broken pixel helpers in the test fixture (related to #2473)

The offscreen fixture's read_pixel and read_region decoded 4 bytes per channel from framebuffer data that has 1 byte per channel, so they returned garbage. read_pixel also ignored its components argument. Nothing used them yet. Both are fixed and now tested.

#2473 also asks for a window-level fetch_pixel API, so this PR doesn't close it.

Tests

  • rand_vec_spread_deg: checks the direction stays within the spread and the length is right, for four angles. 4 of the 4 cases fail on development.
  • Offscreen helpers: new test_offscreen_fixture.py. Both tests fail with the old helpers.
  • GL reads: a 2 GB read isn't practical in a test. The existing texture, framebuffer and buffer read tests pass, and I also checked a texture array read and an offset buffer read by hand.

Full suite: 1761 passed. ruff, mypy and pyright all pass.

The changelog has entries under Unreleased → Fixes.

🤖 Generated with Claude Code

…lpers

- rand_vec_spread_deg passed degrees to Vec2.from_polar, which takes
  radians, so its vectors pointed in random directions (#2648).
- Texture, texture array, framebuffer and buffer reads used
  ctypes.string_at, whose size is a C long: 32 bits on Windows, so
  reads of 2 GB or more failed. They copy with bytes() instead (#2836).
- The offscreen test fixture's read_pixel and read_region decoded 4
  bytes per channel from 1 byte per channel data, and read_pixel
  ignored its components argument (#2473).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvcraven
pvcraven merged commit 306885b into development Oct 8, 2026
7 checks passed
@pvcraven
pvcraven deleted the fix/math-and-gl-reads branch October 8, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant