From 4dd3cf675834bbbd786a638f4427766021dd976d Mon Sep 17 00:00:00 2001 From: gxalpha Date: Sat, 7 Sep 2024 22:12:22 +0200 Subject: [PATCH] libobs: Deprecate obs_scene_sceneitem_from_source 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. --- docs/sphinx/reference-scenes.rst | 5 +++++ libobs/obs.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/reference-scenes.rst b/docs/sphinx/reference-scenes.rst index d8eee24e8a091a..0fe40aeb0de2ef 100644 --- a/docs/sphinx/reference-scenes.rst +++ b/docs/sphinx/reference-scenes.rst @@ -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); diff --git a/libobs/obs.h b/libobs/obs.h index 0e366cc0aa6dc8..23bd3defeb1b60 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -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,