Skip to content

libobs: Keep the transform of an empty bounded group finite - #388

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/4245-empty-group-bounds-nan
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/4245-empty-group-bounds-nan

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

A source added to an empty group that has a bounding box now keeps a finite transform and is drawn in the group's box. Before, its position became NaN, nothing was drawn, and the transform dialog showed 90001 for the source and the group.

  • An empty group has no size. calculate_bounds_data() (libobs/obs-scene.c lines 450-490) found the group's scale by dividing the bounding box by that size, which gave an infinite scale.
  • Moving an item into a group maps it through the group's draw transform (apply_group_transform(), line 3434, which inverts it). With the infinite scale the item's position became NaN and its scale 0, and the group's size was then computed from the NaN item.
  • The same happened with a source that has no size yet (0x0) added to an empty bounded group, and it stayed broken after the source got a size.

The fix, libobs only:

  • The scale half of calculate_bounds_data() moves into a small helper, obs_bounds_fit_scale() in libobs/obs-scene-bounds.[ch], with no scene items in it so it can be tested without a display.
  • Each fit divides only by a size that is not zero. A source with no size on an axis (an empty group, a source that has not loaded, a scale of 0) keeps its scale on that axis. Every result that was finite before is unchanged.

Once the first source is in the group, the group resizes and the bounding box fits it as before.

  1. test/cmocka: Add failing test for sources added to an empty bounded group: two tests. The helper keeps today's arithmetic and is not used by libobs yet.
    • test_scene_bounds_fit (all platforms, no display, no libobs core): 0x0, 0xN and Nx0 sources and a scale of 0 with every bounds type, plus controls with sized sources (fit, base scale, flips, "max only" switching to inner). 4 of 5 fail: a 0x0 source gets scale (inf, inf) with 5 of 6 bounds types, flipped too; 0x100 and 200x0 sources get an infinite scale with stretch, outer, to width or to height; a scale of 0 gives NaN.
    • test_group_empty_bounds (Linux, core video, skips without a display): a real scene with a group at (240, 60) and an 800x600 centred bounding box. A 200x100 source is added with obs_sceneitem_group_add_item (scripts) or obs_scene_reorder_items2 (the Sources dock's drag and drop). The transforms of the source and the group must be finite, the source must be where the bounding box puts it, and the canvas is read back. 12 of 18 fail: both paths with stretch, inner, outer, to width and to height (position NaN, group content 0x0, nothing drawn), and a 0x0 source added to the empty group and grown to 200x100, on both paths. The controls pass: "max only" on both paths, a source and a 0x0 source dragged into a group that already holds one, a source added to a filled group with obs_sceneitem_group_add_item (finite transforms), and an empty group without a bounding box.
  2. libobs: Keep the transform of an empty bounded group finite: 5 of 5 and 18 of 18 pass.

Motivation and Context

Fixes #387 (upstream obsproject/obs-studio#4245, reported by lindenkron, reproduced there by farhanjiwani and flaeri).

Why this one: three people hit it upstream across OBS 26 to 28; the reporter retested it on 28.1.2, and it is still there on 32.2.2 and current master. It was closed as stale, not fixed. Once it happens the group cannot be repaired from the transform dialog, which only shows 90001. The fix is small, in libobs only, and every result that was finite before stays bit-identical. No upstream PR exists. The demand is modest (score 9 in our crawl).

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), on current master:

  • test_scene_bounds_fit: 4 of 5 cases fail at the RED commit and 5 of 5 pass at GREEN, in both lanes. It needs no display and runs in every Tier 2 lane.
  • test_group_empty_bounds: 12 of 18 cases fail at RED and 18 of 18 pass at GREEN, in both lanes, under a private Xvfb with software GL. ctest -V shows all 18 cases run, with no skips, also with the system's libobs-opengl hidden (the test loads the one from the build tree). Without a display every case skips, as CI's Linux lane expects.
  • Full ctest: 125 of 127 at RED (only the two new tests fail) and 127 of 127 at GREEN, in each lane (128 of 128 rebased on current master).
  • clang-format, gersemi and ci/test_registration.py are clean.

Not tested:

  • The running UI. The test drives the same libobs calls as the Sources dock's drag and drop (obs_scene_reorder_items2) and as scripts (obs_sceneitem_group_add_item) and reads the values the transform dialog shows (obs_sceneitem_get_info2); nobody dragged a source into a group by hand.

Not fixed here:

  • obs_sceneitem_group_add_item() (libobs/obs-scene.c line 3766) maps the item through the group's transform (remove_group_transform(), line 3791) before it is in the group. A source added from a script to a group without a bounding box therefore moves by the group's offset (a group at (100, 100): a source at (900, 600) lands at (1000, 700)). Different cause; a bounding box refits the content, so it does not show in the cases above. The control that adds to a filled group with this function checks only that the transforms are finite.
  • 100% repeatable - scene/group layout breaks down, absolute weirdness obsproject/obs-studio#8400 (group layout with centred alignment) was answered upstream as working as designed and does not involve an empty group.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner October 12, 2026 16:10
rdoupe and others added 2 commits October 12, 2026 09:14
…roup

Adding a source to an empty group that has a bounding box gives the
source a NaN transform; the transform dialog shows 90001 for the
source and for the group (reported upstream by lindenkron, reproduced
by farhanjiwani and flaeri). An empty group has no size, and
calculate_bounds_data() in obs-scene.c divides the bounding box by
the size to find the group's scale. The infinite scale makes the
group's draw transform non-invertible, and obs_sceneitem_group_add_item
and obs_scene_reorder_items2 map the added item through it.

obs_bounds_fit_scale() (libobs/obs-scene-bounds.c) is the scale half
of calculate_bounds_data(), kept free of scene items. It is not used
by libobs yet and keeps today's arithmetic.

test_scene_bounds_fit builds the helper on its own (no display, all
platforms). 4 of 5 cases fail:
- empty_source_keeps_scale: a 0x0 source gets scale (inf, inf) with
  every bounds type but "max only" (5 of 6);
- empty_source_keeps_flip: the same with a flip;
- zero_width_or_height_stays_finite: 0x100 and 200x0 sources get an
  infinite scale with stretch, scale outer, to width or to height;
- zero_scale_stays_finite: a base scale of 0 gives NaN.
The control (sized sources fit as before) passes.

test_group_empty_bounds uses a real scene (Linux, core video, skips
without a display): a group at (240, 60) with an 800x600 centred
bounding box, a 200x100 source added with
obs_sceneitem_group_add_item (scripts) or with obs_scene_reorder_items2
(the Sources dock's drag and drop), then checks that the transforms
of the item and the group are finite, that the item is where the
bounding box puts it, and the canvas read back. 12 of 18 cases fail:
both paths with stretch, scale inner, scale outer, scale to width and
scale to height (item pos NaN, group content 0x0, nothing drawn), and
a 0x0 source added to the empty group, then grown to 200x100, with
both paths. The controls pass: "max only" on both paths, a 0x0
source or a source dragged into a group that already holds one, a
source added to a filled group with obs_sceneitem_group_add_item
(finite only), and an empty group without a bounding box.

Refs obs-rust#387 (upstream obsproject/obs-studio#4245).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Adding a source to an empty group that has a bounding box gave the
source a NaN transform, and the transform dialog showed 90001 for the
source and the group (reported upstream by lindenkron). An empty
group has no size, and calculate_bounds_data() divided the bounding
box by that size, so the group's scale was infinite. Moving an item
into the group maps it through the inverse of the group's draw
transform (apply_group_transform), which turned the item's position
into NaN; the group's size was then computed from the NaN item. A
source that had no size yet (0x0) broke the same way and stayed
broken after it got one.

The scale half of calculate_bounds_data() now lives in
obs_bounds_fit_scale() (obs-scene-bounds.c). Each fit divides only by
a size that is not zero: a source with no size on an axis (an empty
group, a source that has not loaded, a scale of 0) keeps its scale
there. Every result that was finite before is unchanged. Once the
first source is in the group, the group resizes and its bounding box
fits it as before.

test_scene_bounds_fit: 5 of 5 pass. test_group_empty_bounds: 18 of
18 pass.

Fixes obs-rust#387 (upstream obsproject/obs-studio#4245).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=4dc5215eb7a96b4f32fa9bd9667a836979656932 secs=130 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791821790,"gate":"rust/all/fmt","host":"linux-x86_64","key":"0542b5b8394230e47ca33c13676765da80894dda22e7d19d4c484bbfcad64b93","lane":"lint","parents":["08721a3bef5b2ba2d339630ae759fe71b4e394c9"],"secs":22,"stamp":"bd9444aeb646071e9451e4cc1f8a0feb","tree":"4dc5215eb7a96b4f32fa9bd9667a836979656932","v":1,"via":"run"}
Ci-Attestation: {"at":1791821790,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"0542b5b8394230e47ca33c13676765da80894dda22e7d19d4c484bbfcad64b93","lane":"lint","parents":["08721a3bef5b2ba2d339630ae759fe71b4e394c9"],"secs":22,"stamp":"84fab33b030217149d695fad9bbb9e49","tree":"4dc5215eb7a96b4f32fa9bd9667a836979656932","v":1,"via":"run"}
Ci-Attestation: {"at":1791821791,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"9f3561fd3c4b34f7dc07b4349cd57a4f8ad0450a9659811e6dafec5b73218435","lane":"rust-test","parents":["08721a3bef5b2ba2d339630ae759fe71b4e394c9"],"secs":47,"stamp":"861200d467d3bb119682a348c9e3005e","tree":"4dc5215eb7a96b4f32fa9bd9667a836979656932","v":1,"via":"run"}
Ci-Attestation: {"at":1791821791,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4058c13cd1dc7001ded466dc45143247531c1f5ccd284d167726f9b6878355de","lane":"tier2-linux","parents":["08721a3bef5b2ba2d339630ae759fe71b4e394c9"],"secs":61,"stamp":"0dd39615b8297bacbfc3567a55605bfe","tree":"4dc5215eb7a96b4f32fa9bd9667a836979656932","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally under xvfb-run (Tier 2 image + mesa):

  • RED 808dc3d: test_scene_bounds_fit fails 4 cases (zero_scale_stays_finite, zero_width_or_height_stays_finite, empty_source_keeps_scale, empty_source_keeps_flip); test_group_empty_bounds fails add_item_scale_inner/outer/to_width/to_height and more
  • GREEN df683d1: test_scene_bounds_fit 5/5, test_group_empty_bounds 18/18

test_group_empty_bounds skips without a display, so plain CI only runs test_scene_bounds_fit. Rebased on master, local gate passed (Tier 2 OFF and ON); pushed as 86451f4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: adding a source to an empty group with a bounding box gives it a NaN transform (upstream #4245)

2 participants