Repository navigation
libobs: Keep the transform of an empty bounded group finite - #388
Merged
Merged
Conversation
…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"}
Member
|
Verified locally under xvfb-run (Tier 2 image + mesa):
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. |
zackees
force-pushed
the
fix/4245-empty-group-bounds-nan
branch
from
October 12, 2026 16:16
df683d1 to
86451f4
Compare
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
calculate_bounds_data()(libobs/obs-scene.clines 450-490) found the group's scale by dividing the bounding box by that size, which gave an infinite scale.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 fix, libobs only:
calculate_bounds_data()moves into a small helper,obs_bounds_fit_scale()inlibobs/obs-scene-bounds.[ch], with no scene items in it so it can be tested without a display.Once the first source is in the group, the group resizes and the bounding box fits it as before.
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 withobs_sceneitem_group_add_item(scripts) orobs_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 withobs_sceneitem_group_add_item(finite transforms), and an empty group without a bounding box.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_LIBOBSOFF 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 -Vshows all 18 cases run, with no skips, also with the system'slibobs-openglhidden (the test loads the one from the build tree). Without a display every case skips, as CI's Linux lane expects.ci/test_registration.pyare clean.Not tested:
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.cline 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.Types of changes
Checklist:
🤖 Generated with Claude Code