Skip to content

Commit

Permalink
libobs: Deprecate obs_scene_sceneitem_from_source
Browse files Browse the repository at this point in the history
obs_scene_sceneitem_from_source is problematic because there can be
multiple items of the same source in a scene, which the function doesn't
account for. In such a case, it would return the first item it finds,
which often might not be what a developer expects.

It was originally added for the undo/redo-operation of "Add New Source"
where the UI guarantees that the item is unique, but for a general case
it's not suitable.
  • Loading branch information
gxalpha committed Sep 11, 2024
1 parent ac8b30d commit 2df0baf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/sphinx/reference-scenes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ Scene Item Functions

:return: The sceneitem associated with a source in a scene. Returns NULL if not found.

.. deprecated:: 31.0
This function is problematic because there can be multiple items of the same source in a scene.
In that case, which of those this function will return is undefined.
If this is the behavior you need, manually use :c:func:`obs_scene_enum_items` instead.

---------------------

.. function:: void obs_sceneitem_set_id(obs_sceneitem_t *item);
Expand Down
4 changes: 2 additions & 2 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,8 @@ EXPORT void obs_sceneitem_save(obs_sceneitem_t *item, obs_data_array_t *arr);
EXPORT void obs_sceneitem_set_id(obs_sceneitem_t *sceneitem, int64_t id);

/** Tries to find the sceneitem of the source in a given scene. Returns NULL if not found */
EXPORT obs_sceneitem_t *obs_scene_sceneitem_from_source(obs_scene_t *scene,
obs_source_t *source);
OBS_DEPRECATED EXPORT obs_sceneitem_t *
obs_scene_sceneitem_from_source(obs_scene_t *scene, obs_source_t *source);

/** Save all the transform states for a current scene's sceneitems */
EXPORT obs_data_t *obs_scene_save_transform_states(obs_scene_t *scene,
Expand Down

0 comments on commit 2df0baf

Please sign in to comment.