Skip to content

libobs: Treat an unknown bounds type as no bounds - #2307

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/bounds-type-range
Oct 25, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/bounds-type-range

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2281

What and why

A scene item bounds type outside OBS_BOUNDS_NONE..OBS_BOUNDS_MAX_ONLY was stored as it came, from four places:

  • a scene collection (scene_load_item());
  • frontend undo data (load_transform_states(), through obs_scene_load_transform_states());
  • obs_sceneitem_set_bounds_type();
  • obs_sceneitem_set_info2().

compute_item_transform() treats any type but OBS_BOUNDS_NONE as bounded, and obs_bounds_fit_scale() leaves the scale alone for a type it doesn't know. So the item drew at its own scale inside a phantom box the size of its bounds, offset by that box's alignment, and the transform dialog showed no bounds type for it.

A new valid_bounds_type() in obs-scene.c.h maps such a value to OBS_BOUNDS_NONE at each of the four entry points:

  • The loads check the int64 they read before any cast, so a value like 2^32 + 2 no longer truncates to SCALE_INNER.
  • The setters check the enum value as int64, which catches a negative value whether the compiler makes the enum signed or unsigned.
  • Valid values are stored unchanged, and no valid scene changes.

What this leaves alone:

  • obs-websocket already maps unknown names to NONE, so it is unchanged.
  • The ported Rust bounds functions (obs-scene::bounds, obs_bounds_fit_scale/obs_bounds_place) are pure and keep their parity with the C. None of the four entry points is ported.
  • The flipped-item cast in compute_item_transform() is a separate item and is not touched here.

RED → GREEN

  • RED commit: cc59706 (test_scene_bounds_type_range, real libobs, graphics suite). On master it fails on all three lanes: C libobs, hybrid libobs and libobs-c-reference (first run on 47c65bb, based on 55ee6e8).
    • set_bounds_type_range and set_info2_range: 20 mismatches each.
    • undo_transform_states_range: 24 mismatches.
    • scene_load_range: 24 mismatches.
    • In each, the out-of-range types read back as given (2^32 + 2 loads as SCALE_INNER), and the item is drawn at (350, 275) instead of (100, 50).
    • valid_types_draw_differently passes, and every valid value round-trips.
  • GREEN: d47844e. test_scene_bounds_type_range passes 5/5 with no skips on C libobs, hybrid libobs and libobs-c-reference. Every scene, group, bounds and transform test, including the websocket transform and bounds tests, also passes: 34/34 on C, 39/39 on hybrid and 39/39 on c-ref. Exported symbols are identical on all three lanes (1766).
  • Real app (UI, protocol output or logging changes): N/A. There is no UI change; the result of a loaded item is covered through obs_load_source() and obs_source_load2().

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

A scene item bounds type outside OBS_BOUNDS_NONE..OBS_BOUNDS_MAX_ONLY
is stored as it comes. compute_item_transform() treats it as bounded
and obs_bounds_fit_scale() leaves the scale alone, so the item draws
at its own scale inside a phantom box the size of its bounds.

test_scene_bounds_type_range puts two items over one 200x100 source in
a scene (scale 1.5, top-left alignment, an 800x600 box aligned to its
centre) and feeds the subject a bounds type through each way one comes
in:

- obs_sceneitem_set_bounds_type();
- obs_sceneitem_set_info2();
- frontend undo data, obs_scene_load_transform_states();
- a scene collection, obs_load_source() and obs_source_load2()
  (scene_load_item()).

The values are every valid type, then 7, 99, -1, INT_MAX, INT_MIN, and
for the loads 2^32 + 2 and INT64_MIN, which a cast to the enum
truncates to 2 and 0. Each must read back (get_bounds_type and
get_info2) as the value if valid, else OBS_BOUNDS_NONE, and the item's
draw and box matrices must equal bit for bit those of the reference
item set directly to that type. valid_types_draw_differently checks
that every valid type but NONE moves this item, so the comparison can
tell them apart.

Without a fix the out-of-range values read back as given (2^32 + 2 as
SCALE_INNER) and draw in the phantom box; the valid values and
INT64_MIN pass.

Refs obs-rust#2281
A scene item bounds type outside OBS_BOUNDS_NONE..OBS_BOUNDS_MAX_ONLY
was stored as it came, from a scene collection (scene_load_item()),
frontend undo data (load_transform_states()),
obs_sceneitem_set_bounds_type() and obs_sceneitem_set_info2().
compute_item_transform() treats any type but OBS_BOUNDS_NONE as
bounded and obs_bounds_fit_scale() leaves the scale alone for a type
it does not know, so the item drew at its own scale inside a phantom
box the size of its bounds, and the transform dialog showed no bounds
type for it.

valid_bounds_type() maps such a value to OBS_BOUNDS_NONE at each of the
four entry points. The loads check the int64 they read before any cast,
so 2^32 + 2 no longer truncates to SCALE_INNER; the setters check the
enum value as int64, which catches a negative value whether the
compiler makes the enum signed or unsigned. Valid values are stored
unchanged. obs-websocket already maps unknown names to NONE and is
unchanged; the Rust bounds functions (obs-scene::bounds) are pure and
keep their parity with the C ones.

Fixes obs-rust#2281
@rdoupe
rdoupe force-pushed the fix/bounds-type-range branch from 47c65bb to d47844e Compare October 25, 2026 02:06
@rdoupe
rdoupe marked this pull request as ready for review October 25, 2026 02:07
@rdoupe
rdoupe requested a review from zackees as a code owner October 25, 2026 02:07
@zackees
zackees enabled auto-merge October 25, 2026 02:11
@zackees
zackees added this pull request to the merge queue Oct 25, 2026
Merged via the queue into obs-rust:master with commit e389f2f Oct 25, 2026
35 checks passed
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: a scene item bounds type outside the enum is kept and draws as an unknown box

2 participants