From 06276288845cf498adcac5da604388e424055495 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 10 May 2022 18:40:47 +0200 Subject: [PATCH] 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 --- source/gfx/shader/gfx-shader.cpp | 4 +- source/obs/obs-tools.cpp | 88 -------------------------------- source/obs/obs-tools.hpp | 2 - 3 files changed, 2 insertions(+), 92 deletions(-) diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index 2447f91c..eb079149 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -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. diff --git a/source/obs/obs-tools.cpp b/source/obs/obs-tools.cpp index 0b4ff37d..11ae4a2d 100644 --- a/source/obs/obs-tools.cpp +++ b/source/obs/obs-tools.cpp @@ -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(el_cur)), name)) - return true; - } - } - - return false; -} - streamfx::obs::tools::child_source::child_source(obs_source_t* parent, std::shared_ptr child) : _parent(parent), _child(child) { diff --git a/source/obs/obs-tools.hpp b/source/obs/obs-tools.hpp index 73917617..f1aba6bd 100644 --- a/source/obs/obs-tools.hpp +++ b/source/obs/obs-tools.hpp @@ -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 _child;