Skip to content

Commit

Permalink
libobs: Change return type for getting filter index
Browse files Browse the repository at this point in the history
This changes the return type for getting the filter index from a
size_t to an int. This makes it easier for developers to use,
as an invalid index just returns a -1.
  • Loading branch information
cg2121 authored and Lain-B committed Jul 20, 2023
1 parent ee530c2 commit cb8b5ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion UI/window-basic-filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ void OBSBasicFilters::FiltersMoved(const QModelIndex &, int srcIdxStart, int,
neighborIdx = 0;

OBSSource neighbor = GetFilter(neighborIdx, isAsync);
size_t idx = obs_source_filter_get_index(source, neighbor);
int idx = obs_source_filter_get_index(source, neighbor);

OBSSource filter = GetFilter(list->currentRow(), isAsync);
obs_source_filter_set_index(source, filter, idx);
Expand Down
8 changes: 4 additions & 4 deletions libobs/obs-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -3294,20 +3294,20 @@ void obs_source_filter_set_order(obs_source_t *source, obs_source_t *filter,
obs_source_dosignal(source, NULL, "reorder_filters");
}

size_t obs_source_filter_get_index(obs_source_t *source, obs_source_t *filter)
int obs_source_filter_get_index(obs_source_t *source, obs_source_t *filter)
{
if (!obs_source_valid(source, "obs_source_filter_get_index"))
return DARRAY_INVALID;
return -1;
if (!obs_ptr_valid(filter, "obs_source_filter_get_index"))
return DARRAY_INVALID;
return -1;

size_t idx;

pthread_mutex_lock(&source->filter_mutex);
idx = da_find(source->filters, &filter, 0);
pthread_mutex_unlock(&source->filter_mutex);

return idx;
return idx != DARRAY_INVALID ? (int)idx : -1;
}

static bool set_filter_index(obs_source_t *source, obs_source_t *filter,
Expand Down
4 changes: 2 additions & 2 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,8 @@ EXPORT void obs_source_filter_set_order(obs_source_t *source,
enum obs_order_movement movement);

/** Gets filter index */
EXPORT size_t obs_source_filter_get_index(obs_source_t *source,
obs_source_t *filter);
EXPORT int obs_source_filter_get_index(obs_source_t *source,
obs_source_t *filter);

/** Sets filter index */
EXPORT void obs_source_filter_set_index(obs_source_t *source,
Expand Down

0 comments on commit cb8b5ba

Please sign in to comment.