Skip to content

rust: Port the scene item order and group membership rules in obs-scene.c to obs-scene #2895

Closed

Description

@rdoupe

Rust port: the scene item order, reorder and group membership decisions of libobs/obs-scene.c.h, moved to Rust (rust/obs-scene, new module item_order, next to item_names, group_transform and transform_update). Every drag in the source tree, every Move Up/Down/Top/Bottom, every group add or remove, and obs-websocket's item index go through them.

Unit

libobs/obs-scene.c.h → libobs/obs-scene-item-order.c.h → rust/obs-scene (item_order).

Phase and position

Phase 5/6 (core), the next slice of obs-scene.c.h in the core-source+ unity group, after the scene transform update decisions (#2874, merged).

Scope

Rust takes over these decisions, each asked where the C makes it today, from the values C reads at that point:

  • obs_sceneitem_set_order: which neighbour the item goes after (down: after prev->prev, or the bottom; up: after next, or after prev; top: after the last item; bottom: the bottom);
  • obs_sceneitem_set_order_position: the bottom for position 0 or an empty list, otherwise how far to walk from the first item (position - 1 steps, stopped at the end of the list by C);
  • obs_sceneitem_get_order_position: whether the item can be looked up;
  • obs_scene_reorder_items: the per-item step of sceneitems_match() (found in the order, and at its own index);
  • obs_scene_reorder_items2: the check of the wanted (group, item) pairs against the current ones, and the group runs (which entries after a group entry go into it);
  • move_active_child(): whether the active child moves (another scene, and the item is active);
  • obs_sceneitem_group_add_item, obs_sceneitem_group_remove_item and obs_sceneitem_group_ungroup2: their membership gates.

C keeps every full_lock/full_unlock, obs_scene_get_ref/release, detach_sceneitem/attach_sceneitem, every prev/next/first_item/parent write, every list walk, build_current_order_info(), move_would_recurse(), remove_group_transform()/apply_group_transform(), resize_group(), the hotkey moves, every signal and every log. Item and group pointers cross as opaque pointers that the core only compares; it never follows one.

Dependencies and existing tests

  • No fix first. Depends on nothing open.
  • Existing real-libobs coverage: test_scene_list_remove, test_scene_enum_items_removal, test_group_recursion, test_group_child_drift, test_group_teardown_uaf, test_group_active_refs, test_group_empty_bounds, test_scene_canvas_characterization and test_scene_dup_group_children.
  • No characterization of the steps yet: test_scene_item_order_steps lands first, on the moved file alone. It pins each movement at the bottom, in the middle, at the top and with one item; positions -1 (after the first item: characterized, not endorsed), 0, 1, the last index, the count and past it; the flat match with the same order, a permutation, a missing, an extra and a repeated item; the pair check and the group runs (sub-items that don't follow their group go to the top level: characterized, not endorsed); the active-child gate; and the add gate (its second check can't be reached: characterized, not endorsed).

Notes

Intentional differences (bug fixes found by reading, none reported by a user), fixed in the GREEN commit and listed in the parity test:

  1. obs_scene_reorder_items2 relinks whatever order it is given once it differs from the current one. An order that leaves out an item unlinks it while its parent still points at the scene, and an item from another scene or one listed twice is linked in as well. Fix: refuse the order unless its items are exactly the scene's current items (top level and in groups), each once. The flat obs_scene_reorder_items already checks this.
  2. obs_sceneitem_set_order with a movement outside enum obs_order_movement detaches the item and never attaches it again. Fix: an unknown movement leaves the item where it was.
  3. obs_sceneitem_group_remove_item doesn't check that the item is in the group: a top-level item or one from another scene gets the group's transform removed and is moved into the group's parent scene. Fix: refuse unless the item's parent is the group's scene, as obs_sceneitem_group_add_item checks its side.
  4. obs_sceneitem_get_order_position and obs_sceneitem_group_ungroup2 read item->parent before any check (and the getter locks a NULL scene for a detached item). Fix: a NULL or detached item gives 0 (the getter) or returns (ungroup2).

obs_scene_insert_group reading items[count - 1] with count 0 is left to its own fix; this unit doesn't touch that line. No user-visible change beyond the fixes above, no exported symbol changes; the new functions are hidden.

Activity

  1. added
    enhancement
    port
    on Oct 29, 2026
  2. rdoupe commented on Oct 29, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #2895 (round 14 unit 1).

    1. Move the decisions to libobs/obs-scene-item-order.c.h (behaviour-neutral, still in libobs.core-source).
    2. Characterization test test_scene_item_order_steps.
    3. Tier 1 RED against todo!() stubs.
    4. GREEN in libobs.ported-scene-item-order, with the four fixes in the issue as intentional differences.
    5. Tier 3 parity with a mutation check.
    6. Docs.

    One PR; a draft opens with the RED commit today. No open PR touches these functions or the core-source+ group.

  3. added
    ready
    on Oct 29, 2026
  4. rdoupe commented on Oct 29, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by the PR that ports the scene item order rules (#2899), merged through the queue.

    What it did: the order, reorder and group membership decisions now live in rust/obs-scene (item_order), with C keeping the locks, walks and link writes. The four intentional fixes listed here are in, each asserted by the parity test.

    What is left, deliberately still C: obs_scene_insert_group()'s item gate and obs_scene_get_group()'s name match (each is a single compare, with no decision of its own to port), and obs_scene_insert_group()'s items[count - 1] read when count is 0, which this unit does not touch.

    Follow-up issue: none filed yet for the items[count - 1] read; it needs its own fix issue.

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

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions