Skip to content

libobs: Treat an out-of-range transition scale type as Max Only - #2080

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/transition-scale-type-range
Oct 24, 2026
Merged

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

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2064

What and why

recalculate_transition_matrix() (libobs/obs-source-transition.c.h) only
sets the fit scale for the three values of enum obs_transition_scale_type.
For any other value the scale stayed uninitialized, so the transition drew
its sources with whatever float the stack held. Two paths stored such a
value unchecked:

  • obs_transition_load(), called by obs_load_sources() with a scene
    collection's "transition_scale_type" (an int64_t, cast straight to the
    enum);
  • obs_transition_set_scale_type(), which stored whatever it was given.

The fix:

  • A small valid_scale_type() maps a value outside the enum to the
    default, OBS_TRANSITION_SCALE_MAX_ONLY, in both the load and the
    setter. Max Only is the value a new transition starts with (the source
    struct is zeroed) and what the getter returns for an invalid transition.
    So the getter and a saved collection now report the scale type the
    transition actually uses.
  • The scale in recalculate_transition_matrix() starts at 1 as a backstop.

The three enum values are stored and fitted exactly as before: the new test
pins the matrices of Max Only, Aspect and Stretch through the setter and
through obs_load_sources(), and they pass unchanged on master.

What users see: a scene collection whose transition has an unknown scale
type (edited by hand or written by another tool) loads with the default fit
instead of an undefined one. The frontend, obs-websocket (no request sets
the scale type) and the bundled plugins can't produce such a value: the
slideshows and scene item show/hide transitions set
OBS_TRANSITION_SCALE_ASPECT, and nothing else calls the setter.

No memory-safety impact: it is a wrong scale, with no pointer or index
involved. Upstream has the same code.

Overlap with #2055 (open, moves the fit math into
obs-source-transition-clock.c.h with a Rust port): this PR is based on
master and changes only the C as it is there, so it does not touch the fit
code #2055 moves. obs-source-transition.c.h merges cleanly with #2055; the
only conflict is the neighbouring test-graph.json entries
(test_transition_clock_steps and test_transition_scale_type), kept both.
After both land, an out-of-range value never reaches
obs_source_transition_clock_fit(), and the backstop scale of 1 also
covers its "scale type outside the enum" case, so its C/Rust parity is
unaffected.

No test expectation changes. Exported symbols stay at 1766 for C, hybrid
and libobs-c-reference. docs/features.md has the line under Fixed
upstream bugs, Scenes and UI.

RED → GREEN

  • RED commit: aa5b786 adds
    test_transition_scale_type (graphics suite, Linux, registered in
    test-graph.json). It fits a 32x16 source into a 64x64 transition, where
    the three scale types give three different matrices, and reads the
    matrix the source is drawn with through
    obs_transition_video_render_direct(). 2 of 4 fail on C, hybrid and
    libobs-c-reference alike (first run on 4ed889d38, the same commit before
    a rebase; re-checked on aa5b786 on C): out_of_range_setter_is_max_only
    (3, -1, INT32_MAX through the setter) and out_of_range_load_is_max_only
    (3, -1 and 2^32 + 2, which an int cast turns into Stretch, through
    obs_load_sources()) fail on the getter (3 != 0). The drawn matrix is
    not a reliable failure on its own: the uninitialized scale is whatever
    the stack holds, and in these runs it happened to match. The two in-range
    cases pass.
  • GREEN: 316255eea4991ad8ba4588a31787978e805c9ffd.
    • test_transition_scale_type 4/4, and test_transition_swap,
      test_studio_mode_swap, test_transition_recursive_destination,
      test_fade_to_color_mix, test_transition_audio_rescale and
      test_stinger_media_duration, on C, hybrid and libobs-c-reference (each
      rebuilt explicitly), on 316255e.
    • Full ctest on 316255e, private Xvfb and D-Bus, fresh HOME:
      C 423/423, hybrid 432/432, 0 skipped. (A run on the pre-rebase head
      hit the intermittent test_context_names segfault of bug: test_context_names segfaults intermittently in test_canvas_sources (Tier 2 Linux, Rust ON) #2049, which
      master has fixed since; the rebased head passed.)
    • Local gate on 316255e: --lane lint ok, --lane cross ok,
      --test-diff origin/master 3076 passed, 2 skipped.
  • Real app (UI, protocol output or logging changes): N/A. No UI, protocol
    or log change; the UI can't set an out-of-range scale type.

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)

Rebased onto master after #2055 (the transition clock port) merged: only the adjacent test-graph.json entries conflicted (both kept, sorted). After it, source::transition* (56 passed), ci/test_test_graph_sorted.py and the lint lane pass. #2055 moved the fit into obs-source-transition-clock.c.h; this PR clamps the scale type before it reaches the fit, so the port's C/Rust parity is unaffected.

@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 07:22
@rdoupe
rdoupe force-pushed the fix/transition-scale-type-range branch from 52db4b4 to bd202bf Compare October 24, 2026 07:22
A transition only sets its fit scale for the three values of enum
obs_transition_scale_type. Any other value leaves the scale in
recalculate_transition_matrix() uninitialized, so the transition draws its
sources with a garbage matrix. obs_load_sources() passes a scene
collection's "transition_scale_type" to the transition unchecked, and
obs_transition_set_scale_type() stores whatever it is given.

test_transition_scale_type fits a 32x16 source into a 64x64 transition,
where Max Only, Aspect and Stretch give three different matrices, and reads
the matrix the source is drawn with through
obs_transition_video_render_direct(). Its four cases:
- in_range_setter_unchanged, in_range_load_unchanged: the three enum
  values, through the setter and through obs_load_sources(), keep their
  current matrix and getter value. These pass already and guard the fix.
- out_of_range_setter_is_max_only: 3, -1 and INT32_MAX through the setter.
- out_of_range_load_is_max_only: 3, -1 and 2^32 + 2 (which an int cast
  would turn into Stretch) through obs_load_sources().
The out-of-range cases expect the default, Max Only: its matrix, the
getter, and for the loaded transition, the value it saves.

Needs core video, so it runs under xvfb-run on Linux and skips without a
display.

Fails as expected on the C backend, hybrid libobs and libobs-c-reference:
2 of 4. Both out-of-range cases fail on the getter (3 != 0). The drawn
matrix is not a reliable failure: the uninitialized scale is whatever the
stack holds, and here it happened to match.

Refs obs-rust#2064
recalculate_transition_matrix() only sets the fit scale for the three
values of enum obs_transition_scale_type, so any other value left it
uninitialized and the transition drew its sources with a garbage matrix.
obs_transition_load() took the value from a scene collection unchecked,
and obs_transition_set_scale_type() stored whatever it was given.

Both now store the default, OBS_TRANSITION_SCALE_MAX_ONLY (the value a new
transition starts with and the getter returns for an invalid transition),
for a value outside the enum, so the getter and a saved collection report
the scale type the transition uses. The three enum values are stored as
before. The scale in recalculate_transition_matrix() starts at 1 as a
backstop.

Nothing in the frontend, obs-websocket or the bundled plugins sets an
out-of-range value: the slideshows and scene item show/hide transitions
set OBS_TRANSITION_SCALE_ASPECT.

test_transition_scale_type passes 4 of 4 on the C backend, hybrid libobs
and libobs-c-reference.

Fixes obs-rust#2064
@rdoupe
rdoupe force-pushed the fix/transition-scale-type-range branch from bd202bf to 316255e Compare October 24, 2026 07:34
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit 2fc37ac Oct 24, 2026
31 checks passed
@rdoupe rdoupe mentioned this pull request Oct 27, 2026
6 of 7 tasks
rdoupe added a commit that referenced this pull request Oct 27, 2026
Behaviour-neutral extraction before the Rust port. The decisions of
transition_valid(), valid_scale_type(), obs_transition_load(),
copy_source_state(), obs_transition_swap_begin() and
obs_transition_swap_end() in obs-source-transition.c.h move to
libobs/obs-source-transition-load.c.h, as six functions on plain values
declared in the new libobs/obs-source-transition-load.h without EXPORT
(hidden, as -fvisibility=hidden keeps them):

- _is_transition(): the type check of transition_valid(), after
  obs_ptr_valid();
- _scale_type(): valid_scale_type(), used by
  obs_transition_set_scale_type() and obs_transition_load(): 0, 1 and 2
  as they are, any other int64_t Max Only;
- _looks_up(): obs_transition_load() looks its saved source up only
  with a name;
- _source() -> KEEP | NOT_FOUND | REFUSE: what the load does with the
  looked-up source after the add (the add only for a found source);
- _swaps(): the swap of a transition with itself does nothing, in both
  swap_begin() and swap_end();
- _copy_stores(): copy_source_state() stores the new child unless it
  was to be added as an active child and the add failed.

obs_transition_load()'s release of the old source A (#2584) asks
obs_source_transition_start_child_active(), the rule
copy_source_state() and obs_transition_set() already ask.

Split per step, as #2153 did, so every call and read stays where it was
and under its condition: obs_ptr_valid(), the locks and their order,
the pointer comparisons, the obs_data reads at the top, the lookup, the
add only for a found source or an active new child (the C's own &&),
every obs_source_get_ref() and obs_source_release(), the active child
calls, the (uint32_t) truncations of the loaded alignment and size, the
mode taken as is, the fields the swap hands over, the texrender swap,
recalculate_transition_size() and _matrices(), and the logs. The
getters' answers for an invalid transition (Max Only, 0, 0x0 and
false) stay C as the literals they are. The source type and the scale
type cross as int; the header copies OBS_SOURCE_TYPE_TRANSITION and the
three scale types, and obs-source-transition.c.h checks them and that
enum obs_source_type is int-sized with _Static_assert (the scale type
enum is already checked there).

Checked in a scratch harness (not committed). It compiles
origin/master's transition_valid(), valid_scale_type(),
obs_transition_set_scale_type(), obs_transition_get_scale_type(),
obs_transition_get_alignment(), obs_transition_get_size(),
obs_transition_fixed(), obs_transition_load(), copy_source_state(),
obs_transition_swap_begin() and obs_transition_swap_end() verbatim next
to this branch's and the moved file, as C++, over stand-in sources whose
fields log every read and write with its value. Every call is logged in
order with its arguments: both mutexes of both transitions (lock and
unlock), obs_ptr_valid(), the obs_data reads, obs_get_source_by_name()
(which may find nothing), obs_source_add_active_child() (which may
fail), obs_source_remove_active_child(), obs_source_get_ref() (which
may return NULL), obs_source_release(), obs_source_get_name(), blog(),
obs_transition_clear() and the size and matrix recalculation. Another
thread may write a source, a slot flag, the scale type, the fixed flag,
the width or the video flag at any lock, unlock or call. Inputs: two
transitions and four children of any source type (including values out
of the enum), every slot empty or any child and active or not, no
source, the transition swapped with itself or the other, names that are
missing, unknown, a child or a transition, and loaded and set values at
0, 1, 2, 3, -1, 7, 255, 2^31, around 2^32, the ends of int64_t and
random; one to four operations each.

5,800,000 runs: 2,000,000 each with GCC and Clang at -O2, 500,000 each
at -O0, 300,000 each under ASan and UBSan with no recovery (GCC -O0,
Clang -O2) and 200,000 with gcov. All 149,390,395 logged events match,
as does the final state (every field, reference and active reference).
Every branch of origin/master's functions is taken both ways.

24 deliberately broken moves were planted, and all 24 fail it: each
function's rule inverted, widened or made constant (the type at >= 2,
STRETCH dropped, the default ASPECT, the value's low bit, the lookup
always or never, NOT_FOUND and REFUSE swapped or made KEEP, the swap
always or for the same transition, the store rule as add_ok, !adds &&
add_ok, adds || add_ok and !adds), and at the call sites the add for a
source not found, the add for an inactive or missing new child, the old
source A removed when inactive, the type check on a constant, the scale
type taken mod 3 and the lookup without a name.

git blame on the moved lines shows the upstream commits 6839ff7 and
a1fbf10, and the fork's #2080 (the scale type rule), #2513 (the swap
refusal) and #2584 (the release of the old source A); they move as they
are.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header; source-sets.json lists it. docs/rust-port/naming.md
already maps libobs/obs-source*.c.h to rust/obs-source. The exported
symbol set is unchanged (1766 on the C backend); the six functions are
local.

Refs #2595.
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
* libobs: Move the transition load decisions

Behaviour-neutral extraction before the Rust port. The decisions of
transition_valid(), valid_scale_type(), obs_transition_load(),
copy_source_state(), obs_transition_swap_begin() and
obs_transition_swap_end() in obs-source-transition.c.h move to
libobs/obs-source-transition-load.c.h, as six functions on plain values
declared in the new libobs/obs-source-transition-load.h without EXPORT
(hidden, as -fvisibility=hidden keeps them):

- _is_transition(): the type check of transition_valid(), after
  obs_ptr_valid();
- _scale_type(): valid_scale_type(), used by
  obs_transition_set_scale_type() and obs_transition_load(): 0, 1 and 2
  as they are, any other int64_t Max Only;
- _looks_up(): obs_transition_load() looks its saved source up only
  with a name;
- _source() -> KEEP | NOT_FOUND | REFUSE: what the load does with the
  looked-up source after the add (the add only for a found source);
- _swaps(): the swap of a transition with itself does nothing, in both
  swap_begin() and swap_end();
- _copy_stores(): copy_source_state() stores the new child unless it
  was to be added as an active child and the add failed.

obs_transition_load()'s release of the old source A (obs-rust#2584) asks
obs_source_transition_start_child_active(), the rule
copy_source_state() and obs_transition_set() already ask.

Split per step, as obs-rust#2153 did, so every call and read stays where it was
and under its condition: obs_ptr_valid(), the locks and their order,
the pointer comparisons, the obs_data reads at the top, the lookup, the
add only for a found source or an active new child (the C's own &&),
every obs_source_get_ref() and obs_source_release(), the active child
calls, the (uint32_t) truncations of the loaded alignment and size, the
mode taken as is, the fields the swap hands over, the texrender swap,
recalculate_transition_size() and _matrices(), and the logs. The
getters' answers for an invalid transition (Max Only, 0, 0x0 and
false) stay C as the literals they are. The source type and the scale
type cross as int; the header copies OBS_SOURCE_TYPE_TRANSITION and the
three scale types, and obs-source-transition.c.h checks them and that
enum obs_source_type is int-sized with _Static_assert (the scale type
enum is already checked there).

Checked in a scratch harness (not committed). It compiles
origin/master's transition_valid(), valid_scale_type(),
obs_transition_set_scale_type(), obs_transition_get_scale_type(),
obs_transition_get_alignment(), obs_transition_get_size(),
obs_transition_fixed(), obs_transition_load(), copy_source_state(),
obs_transition_swap_begin() and obs_transition_swap_end() verbatim next
to this branch's and the moved file, as C++, over stand-in sources whose
fields log every read and write with its value. Every call is logged in
order with its arguments: both mutexes of both transitions (lock and
unlock), obs_ptr_valid(), the obs_data reads, obs_get_source_by_name()
(which may find nothing), obs_source_add_active_child() (which may
fail), obs_source_remove_active_child(), obs_source_get_ref() (which
may return NULL), obs_source_release(), obs_source_get_name(), blog(),
obs_transition_clear() and the size and matrix recalculation. Another
thread may write a source, a slot flag, the scale type, the fixed flag,
the width or the video flag at any lock, unlock or call. Inputs: two
transitions and four children of any source type (including values out
of the enum), every slot empty or any child and active or not, no
source, the transition swapped with itself or the other, names that are
missing, unknown, a child or a transition, and loaded and set values at
0, 1, 2, 3, -1, 7, 255, 2^31, around 2^32, the ends of int64_t and
random; one to four operations each.

5,800,000 runs: 2,000,000 each with GCC and Clang at -O2, 500,000 each
at -O0, 300,000 each under ASan and UBSan with no recovery (GCC -O0,
Clang -O2) and 200,000 with gcov. All 149,390,395 logged events match,
as does the final state (every field, reference and active reference).
Every branch of origin/master's functions is taken both ways.

24 deliberately broken moves were planted, and all 24 fail it: each
function's rule inverted, widened or made constant (the type at >= 2,
STRETCH dropped, the default ASPECT, the value's low bit, the lookup
always or never, NOT_FOUND and REFUSE swapped or made KEEP, the swap
always or for the same transition, the store rule as add_ok, !adds &&
add_ok, adds || add_ok and !adds), and at the call sites the add for a
source not found, the add for an inactive or missing new child, the old
source A removed when inactive, the type check on a constant, the scale
type taken mod 3 and the lookup without a name.

git blame on the moved lines shows the upstream commits 6839ff7 and
a1fbf10, and the fork's obs-rust#2080 (the scale type rule), obs-rust#2513 (the swap
refusal) and obs-rust#2584 (the release of the old source A); they move as they
are.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header; source-sets.json lists it. docs/rust-port/naming.md
already maps libobs/obs-source*.c.h to rust/obs-source. The exported
symbol set is unchanged (1766 on the C backend); the six functions are
local.

Refs obs-rust#2595.

* test: Characterize the transition load checks

test_transition_load_steps compiles
libobs/obs-source-transition-load.c.h and
libobs/obs-source-transition-start.c.h (ASan and UBSan) and calls only
their functions through the two headers. 10 cases:

- the header's copies of OBS_SOURCE_TYPE_TRANSITION and the three scale
  types, the enums' sizes and the source outcome values;
- the type check: only 2, over -1000..1000 and the ends of int;
- the scale type: 0, 1 and 2 as they are, anything else Max Only (3,
  -1, the ends of int32_t and int64_t, -1000..1000), compared in 64
  bits (2^32 + 1 and 2^32 + 2 are Max Only, not Aspect or Stretch);
- the load's lookup and source outcome, the swap gate and
  copy_source_state()'s store rule over every combination.

obs_transition_load(), copy_source_state() with the swap, the getters
and obs_transition_set_scale_type() are also copied onto a stand-in
transition whose children count their references and active
references and refuse an add to a transition they contain, to pin end
to end: the loaded fields; a missing name (no lookup, no warning), an
unknown or empty name (none and a warning), a known source (kept, one
reference and one active reference), a source that contains the
transition (released, none and a warning, and the old source A still
goes out); a load onto a slot A that holds a source (taken back), the
same source again and an inactive slot A (released without a removal);
the swap with itself (nothing); all 32 slot states of the swap (old
child present and active or not, new child present, active and
contained or not), each child left with the right references and the
refusal storing none, inactive; and the getters and the setter on a
source of every type and on none.

Characterized, not endorsed:
- the loaded alignment, width and height are truncated to their low 32
  bits: 2^32 + 5 loads as 5, -1 as UINT32_MAX, INT64_MIN as 0;
- the loaded mode is kept as is: 7 stays 7.

It is in the native test graph, in name order, with both headers as
watch inputs. No assert_in_range or fail_msg, so it builds with cmocka
1.x and 2.x, and no two enum types are compared. The real-libobs tests
test_transition_load_release, test_transition_scale_type,
test_transition_swap, test_transition_swap_active and
test_transition_swap_cycle cover the callers.

Refs obs-rust#2595.

* obs-source: Test the transition_load port

RED for the port of libobs/obs-source-transition-load.c.h to a new
transition_load module of rust/obs-source, next to transition_clock,
transition_render and transition_start. The safe core is a stub
(todo!()): is_transition(), scale_type(), looks_up(), source() ->
Source (Keep, NotFound, Refuse), swaps() and copy_stores(), with
TYPE_TRANSITION and the scale types (taken from transition_clock).

The plan sketched wider steps: load_fields() for the five loaded
values, load_source(has_name, found, add_ok), release_old(), swap()
and copy_slot(has_old, old_active, child_active, add_ok). The
truncations and the mode stay C casts, so load_fields() comes down to
scale_type(). load_source() and copy_slot() would take the add's
result before the C knows whether it adds at all; so the lookup, the
outcome after the add and the store rule are their own functions, and
the C keeps its && before each add. release_old() is
transition_start::child_active(), already ported, and the getters'
defaults stay C literals.

tests/source/transition_load.rs ports test_transition_load_steps 1:1:
its 10 cases under the same names (steps_*), in the same order, with
the same values and expectations, the characterized-not-endorsed cases
and the stand-in transition's copies of the callers included.

Edge cases (edge_*) check the core against models of the original C:
- every decision over every combination of its flags;
- the type check over -100,000..100,000, the ends of i32 and 2 with any
  other bit set;
- the scale type at every power of two with its neighbours and
  negations, a stride over i64 and the ends, against origin/master's
  valid_scale_type();
- proptests (4,096 cases each): every decision over full-range values,
  and sequences of up to eleven loads (any name, any int64_t values),
  swaps, swap_begin()s and swap_end()s alone, scale type sets and
  getter reads on three transitions of any source type with children
  that may contain them, through the stand-in against a copy of the
  callers with origin/master's expressions inline; both end in the same
  state, and every child's references match the slots that hold it.

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_load passes 1 of 15 (the constants) and fails 14
with "not yet implemented".

Refs obs-rust#2595.

* obs-source: Port the transition load checks

Ports libobs/obs-source-transition-load.c.h, the load, scale type and
swap checks of obs-source-transition.c, to the transition_load module
of rust/obs-source. obs-source-transition.c.h stays C around it:
obs_ptr_valid(), the locks and the texture locks in their order, the
pointer comparisons, the obs_data reads, obs_get_source_by_name(), the
add only for a found source or an active new child, every
obs_source_get_ref() and obs_source_release(), the active child calls,
the (uint32_t) truncations and the mode taken as is, the fields the
swap hands over, the texrender swap, the size and matrix
recalculation, the getters' literals and the logs. The hybrid libobs
drops the C file and links the Rust shims in its place.

Safe core (src/transition_load.rs), six functions:
- is_transition(): type == TYPE_TRANSITION (2);
- scale_type(): 1 and 2 as Aspect and Stretch, any other i64 Max Only,
  matched on the whole i64 (2^32 + 1 is not Aspect);
- looks_up(): has_name; swaps(): !same;
- source() -> Source: NotFound without a source, Refuse when the add
  failed, else Keep;
- copy_stores(): !adds || add_ok.
TYPE_TRANSITION is the header's; the scale types are transition_clock's.
The module denies clippy's arithmetic, indexing, as, unwrap, expect,
panic, todo, unimplemented and unreachable lints, keeps no state and
takes no lock.

Shims (src/ffi/source_transition_load.rs): the six C signatures by
value; the source type and the scale type result as int, the loaded
scale type as int64_t, the outcome as the C's enum (u32, as
source_transition_start returns its admission). No pointer crosses and
no struct is mirrored. No intentional difference from the C.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-transition-load (LIBOBS_PORTED_SOURCES), whose PCH
is only obs-source-transition-load.h; libobs.pch.h keeps the header for
obs-source-transition.c. The functions are not EXPORT, so the shims are
hidden: rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. libobs-rust already links the crate's ffi.
The exported symbol sets are unchanged and equal: 1766 on the C
backend, the hybrid and libobs-c-reference; the six functions are local
in all three, and the hybrid's come from the Rust archive (the group's
object is built only for libobs-c-reference). ci/test_ported_sources.py
checks the group on every host.

test_transition_load_steps still compiles the C file into itself,
unchanged. The new test_transition_load_steps_rust builds the same test
source against libobs_rust-static instead, as
test_transition_start_steps_rust does, and links: the test includes the
two headers and obs.h and calls only hidden functions. The 28
transition tests (test_transition_*, test_studio_mode_swap,
test_studio_mode_exit, test_saved_transition, test_tbar_position,
test_fade_to_color_mix, test_visibility_transition,
test_stinger_media_duration, test_item_transition_empty_source,
test_group_hide_transition_audio and test_slideshow_manual_end, with
the _rust variants) pass on the C backend, the hybrid and
libobs-c-reference.

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_load:: passes 15 of 15.

No user-visible change, so no docs/features.md line.

Refs obs-rust#2595.

* obs-source: Check transition_load against the C

Tier 3 for the transition_load port. oracle/source_transition_load.c
compiles the unmodified libobs/obs-source-transition-load.c.h with its
six functions renamed to oracle_*, and exports the header's values and
sizes by index. tests/source/transition_load_parity.rs gives each input
to the oracle, the shim (the extern "C" function the hybrid links) and
the core, and compares each bool as the C's byte (0 or 1, the same on
both sides), the outcome as the C's enum value and each number
exactly:

- the header's values and the sizes of the outcome enum, bool and int;
- every function of flags over every combination of them;
- the type check over every int from -1,000,000 to 1,000,000, every
  65,521st int, 2 with each other bit set and the ends;
- the scale type over every value from -1,000,000 to 1,000,000, every
  power of two with its neighbours and negations, the 65,536 values
  either side of 2^32 and -2^32, the 65,536 at each end of int64_t and
  a stride over int64_t;
- proptests (20,000 cases each) over any int type, any int64_t scale
  type and any flags.

Nothing is excluded: the C has no undefined or host-dependent result
here, and the port has no intentional difference.

Mutation check: 23 mutants, all killed. 16 in the core (the type check
at >= and !=, each scale type mapped wrong, the default Aspect, the
value's low 32 bits matched, the lookup always or never, each source
outcome inverted or swapped, the swap gate inverted or constant, and
the store rule as add_ok, !adds && add_ok and adds || add_ok): Tier 1
and Tier 3 each kill all 16. 7 in the shims (a constant type, the
scale type's low 32 bits, a constant lookup, the source and store
arguments swapped, KEEP returned as REFUSE, the swap gate inverted):
Tier 3 kills all 7 (Tier 1 calls only the core).

Refs obs-rust#2595.

* docs: Record the transition load port

rust/README.md gets the row for libobs/obs-source-transition-load.c.h
(obs-source::transition_load), in sorted place: what moved, what stays
C and why (every read and call at its point and under its condition,
the add only under the C's own &&, the truncating casts, the swap's
handover and the getters' literals), the characterized-not-endorsed
behaviours, the tests that see the swap and what Tier 3 covers. The
obs-source crate row, its Cargo description and the lib.rs crate docs
name the new module. docs/rust-port/naming.md already maps
libobs/obs-source*.c.h to rust/obs-source.

rust/obs-c-oracle/benches/port_comparison/source_transition_load.rs
runs 1024 loads over every combination of the flags the C reads,
source types in and out of the enum and saved scale types at 0, 1, 2,
3, -1 and past 32 bits, each through the type check, the lookup, the
source outcome and the scale type, then a swap's gate and the store
rule of both slots, on the shims and on the oracle, and checks both
checksums match. Release, x86_64 Linux, GCC, a loaded host, median per
1024 loads: Rust 16.99 us, C 16.72 us (1.02x), about 17 ns a load.

The port changes nothing a user can see, so docs/features.md has no
line.

Fixes obs-rust#2595.
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: an out-of-range transition scale type gives an uninitialized scale

2 participants