obs/tools: Remove work-around for obs_properties_remove_by_name

The bug fix to this was applied upstream, so we no longer need to support the broken behavior
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2022-05-10 18:40:47 +02:00
parent 98e2447ec8
commit 0627628884
3 changed files with 2 additions and 92 deletions

View File

@ -261,7 +261,7 @@ bool streamfx::gfx::shader::shader::on_refresh_properties(obs_properties_t* prop
{ // Clear parameter options.
auto grp = obs_property_group_content(obs_properties_get(props, ST_KEY_PARAMETERS));
for (auto p = obs_properties_first(grp); p != nullptr; p = obs_properties_first(grp)) {
streamfx::obs::tools::obs_properties_remove_by_name(grp, obs_property_name(p));
obs_properties_remove_by_name(grp, obs_property_name(p));
}
// Rebuild new parameters.
@ -302,7 +302,7 @@ bool streamfx::gfx::shader::shader::on_shader_or_technique_modified(obs_properti
// Clear parameter options.
auto grp = obs_property_group_content(obs_properties_get(props, ST_KEY_PARAMETERS));
for (auto p = obs_properties_first(grp); p != nullptr; p = obs_properties_first(grp)) {
streamfx::obs::tools::obs_properties_remove_by_name(grp, obs_property_name(p));
obs_properties_remove_by_name(grp, obs_property_name(p));
}
// Rebuild new parameters.

View File

@ -82,94 +82,6 @@ bool streamfx::obs::tools::scene_contains_source(obs_scene_t* scene, obs_source_
return sd.found;
}
extern "C" {
struct _hack_obs_properties;
struct _hack_obs_property {
char* name;
char* desc;
char* long_desc;
void* priv;
enum obs_property_type type;
bool visible;
bool enabled;
struct _hack_obs_properties* parent;
obs_property_modified_t modified;
obs_property_modified2_t modified2;
struct _hack_obs_property* next;
};
struct _hack_obs_properties {
void* param;
void (*destroy)(void* param);
uint32_t flags;
struct _hack_obs_property* first_property;
struct _hack_obs_property** last;
struct _hack_obs_property* parent;
};
}
bool streamfx::obs::tools::obs_properties_remove_by_name(obs_properties_t* props, const char* name)
{
// Due to a bug in obs_properties_remove_by_name, calling it on the first or last element of a group corrupts the
// obs_properties_t's first and last pointers, which now point at nonsense.
//
// There are two ways to work around this issue for now:
// 1. Add some invisible properties to the beginning and end of the list, ensuring that you never hit the first or
// last element with a obs_properties_remove_by_name.
// 2. Manually adjust the pointers using a dirty hack like in gs::mipmapper.
// I've opted for the 2nd way, at it is way simpler to implement.
// Assume that this is fixed in libobs 24.0.7 or newer.
if (obs_get_version() >= MAKE_SEMANTIC_VERSION(24, 0, 7)) {
::obs_properties_remove_by_name(props, name);
return true;
}
auto rprops = reinterpret_cast<_hack_obs_properties*>(props);
for (_hack_obs_property *el_prev = rprops->first_property, *el_cur = el_prev; el_cur != nullptr;
el_prev = el_cur, el_cur = el_cur->next) {
if (strcmp(el_cur->name, name) == 0) {
// Store some information.
_hack_obs_property* next = el_cur->next;
bool is_first = (rprops->first_property == el_cur);
bool is_last = (rprops->last == &el_cur->next);
bool is_solo = (el_cur == el_prev);
// Call the real one which fixes the element pointer and deallocates the element.
::obs_properties_remove_by_name(props, name);
// Fix up the memory pointers after the element was deleted.
if (is_last) {
if (is_solo) {
rprops->last = &rprops->first_property;
} else {
rprops->last = &el_prev->next;
}
}
if (is_first) {
rprops->first_property = next;
}
// Finally break out as we no longer have to process the properties list.
return true;
}
if (el_cur->type == OBS_PROPERTY_GROUP) {
if (streamfx::obs::tools::obs_properties_remove_by_name(
obs_property_group_content(reinterpret_cast<obs_property_t*>(el_cur)), name))
return true;
}
}
return false;
}
streamfx::obs::tools::child_source::child_source(obs_source_t* parent, std::shared_ptr<obs_source_t> child)
: _parent(parent), _child(child)
{

View File

@ -24,8 +24,6 @@ namespace streamfx::obs {
namespace tools {
bool scene_contains_source(obs_scene_t* scene, obs_source_t* source);
bool obs_properties_remove_by_name(obs_properties_t* props, const char* name);
class child_source {
obs_source_t* _parent;
std::shared_ptr<obs_source_t> _child;