From b8f23fa8ab2b7997471f21d4a76a42fc62f604dc Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 7 Sep 2021 04:22:46 +0200 Subject: [PATCH] project: Don't leak exceptions if possible --- source/filters/filter-blur.cpp | 29 ++++++++++++- source/filters/filter-color-grade.cpp | 41 +++++++++++++++---- source/filters/filter-displacement.cpp | 21 +++++++++- source/filters/filter-dynamic-mask.cpp | 29 ++++++++++++- source/filters/filter-nv-face-tracking.cpp | 26 +++++++++--- source/filters/filter-sdf-effects.cpp | 33 ++++++++++++--- source/filters/filter-shader.cpp | 29 ++++++++++++- source/filters/filter-transform.cpp | 29 ++++++++++++- .../filters/filter-video-superresolution.cpp | 14 ++++++- source/sources/source-mirror.cpp | 34 +++++++++++++-- source/sources/source-shader.cpp | 29 ++++++++++++- source/transitions/transition-shader.cpp | 29 ++++++++++++- 12 files changed, 306 insertions(+), 37 deletions(-) diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index ae82479..61621a0 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -31,6 +31,21 @@ #include "gfx/blur/gfx-blur-gaussian.hpp" #include "obs/gs/gs-helper.hpp" #include "obs/obs-source-tracker.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif // OBS #ifdef _MSC_VER @@ -880,18 +895,28 @@ std::string blur_factory::translate_string(const char* format, ...) #ifdef ENABLE_FRONTEND bool blur_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _filter_blur_factory_instance = nullptr; void streamfx::filter::blur::blur_factory::initialize() -{ +try { if (!_filter_blur_factory_instance) _filter_blur_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::blur::blur_factory::finalize() diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index eefbc3e..a81667a 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -21,6 +21,21 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif // OBS #ifdef _MSC_VER @@ -110,8 +125,6 @@ static constexpr std::string_view HELP_URL = "https://github.com/Xaymar/obs-Stre // TODO: Figure out a way to merge _lut_rt, _lut_texture, _rt_source, _rt_grad, _tex_source, _tex_grade, _source_updated and _grade_updated. // Seriously this is too much GPU space wasted on unused trash. -#define ST_PREFIX " " - color_grade_instance::~color_grade_instance() {} color_grade_instance::color_grade_instance(obs_data_t* data, obs_source_t* self) @@ -127,13 +140,13 @@ color_grade_instance::color_grade_instance(obs_data_t* data, obs_source_t* self) // Load the color grading effect. auto path = streamfx::data_file_path("effects/color-grade.effect"); if (!std::filesystem::exists(path)) { - DLOG_ERROR(ST_PREFIX "Failed to locate effect file '%s'.", path.u8string().c_str()); + D_LOG_ERROR("Failed to locate effect file '%s'.", path.u8string().c_str()); throw std::runtime_error("Failed to load color grade effect."); } else { try { _effect = streamfx::obs::gs::effect::create(path.u8string()); } catch (std::exception const& ex) { - DLOG_ERROR(ST_PREFIX "Failed to load effect '%s': %s", path.u8string().c_str(), ex.what()); + D_LOG_ERROR("Failed to load effect '%s': %s", path.u8string().c_str(), ex.what()); throw; } } @@ -144,7 +157,7 @@ color_grade_instance::color_grade_instance(obs_data_t* data, obs_source_t* self) _lut_consumer = std::make_shared(); _lut_initialized = true; } catch (std::exception const& ex) { - DLOG_WARNING(ST_PREFIX "Failed to initialize LUT rendering, falling back to direct rendering.\n%s", ex.what()); + D_LOG_WARNING("Failed to initialize LUT rendering, falling back to direct rendering.\n%s", ex.what()); _lut_initialized = false; } @@ -152,7 +165,7 @@ color_grade_instance::color_grade_instance(obs_data_t* data, obs_source_t* self) try { allocate_rendertarget(GS_RGBA); } catch (std::exception const& ex) { - DLOG_ERROR(ST_PREFIX "Failed to acquire render target for rendering: %s", ex.what()); + D_LOG_ERROR("Failed to acquire render target for rendering: %s", ex.what()); throw; } @@ -487,7 +500,7 @@ void color_grade_instance::video_render(gs_effect_t* shader) _lut_rt.reset(); _lut_texture.reset(); _lut_enabled = false; - DLOG_WARNING(ST_PREFIX "Reverting to direct rendering due to error: %s", ex.what()); + D_LOG_WARNING("Reverting to direct rendering due to error: %s", ex.what()); } } if ((!_lut_initialized || !_lut_enabled) && !_cache_fresh) { @@ -868,18 +881,28 @@ obs_properties_t* color_grade_factory::get_properties2(color_grade_instance* dat #ifdef ENABLE_FRONTEND bool color_grade_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _color_grade_factory_instance = nullptr; void streamfx::filter::color_grade::color_grade_factory::initialize() -{ +try { if (!_color_grade_factory_instance) _color_grade_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::color_grade::color_grade_factory::finalize() diff --git a/source/filters/filter-displacement.cpp b/source/filters/filter-displacement.cpp index cd608d2..4af803c 100644 --- a/source/filters/filter-displacement.cpp +++ b/source/filters/filter-displacement.cpp @@ -22,6 +22,21 @@ #include #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif #define ST_I18N "Filter.Displacement" #define ST_I18N_FILE "Filter.Displacement.File" @@ -165,9 +180,13 @@ obs_properties_t* displacement_factory::get_properties2(displacement_instance* d std::shared_ptr _filter_displacement_factory_instance = nullptr; void streamfx::filter::displacement::displacement_factory::initialize() -{ +try { if (!_filter_displacement_factory_instance) _filter_displacement_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::displacement::displacement_factory::finalize() diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 3f44452..2ff2942 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -23,6 +23,21 @@ #include #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif // Filter to allow dynamic masking // Allow any channel to affect any other channel @@ -520,18 +535,28 @@ std::string dynamic_mask_factory::translate_string(const char* format, ...) #ifdef ENABLE_FRONTEND bool dynamic_mask_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _filter_dynamic_mask_factory_instance = nullptr; void streamfx::filter::dynamic_mask::dynamic_mask_factory::initialize() -{ +try { if (!_filter_dynamic_mask_factory_instance) _filter_dynamic_mask_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::dynamic_mask::dynamic_mask_factory::finalize() diff --git a/source/filters/filter-nv-face-tracking.cpp b/source/filters/filter-nv-face-tracking.cpp index 6d117c0..8c3088e 100644 --- a/source/filters/filter-nv-face-tracking.cpp +++ b/source/filters/filter-nv-face-tracking.cpp @@ -24,6 +24,21 @@ #include "nvidia/cuda/nvidia-cuda-context.hpp" #include "obs/gs/gs-helper.hpp" #include "obs/obs-tools.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif #define ST_I18N "Filter.NVIDIA.FaceTracking" #define ST_I18N_ROI ST_I18N ".ROI" @@ -706,12 +721,13 @@ std::shared_ptr<::streamfx::nvidia::ar::ar> face_tracking_factory::get_ar() std::shared_ptr _filter_nvidia_face_tracking_factory_instance = nullptr; void streamfx::filter::nvidia::face_tracking_factory::initialize() -{ - try { +try { + if (!_filter_nvidia_face_tracking_factory_instance) _filter_nvidia_face_tracking_factory_instance = std::make_shared(); - } catch (const std::exception& ex) { - DLOG_ERROR(" %s", ex.what()); - } +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::nvidia::face_tracking_factory::finalize() diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index 1395bad..10fc19f 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -21,8 +21,21 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" -#define ST_PREFIX " " +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif // Translation Strings #define ST_I18N "Filter.SDFEffects" @@ -136,8 +149,8 @@ sdf_effects_instance::sdf_effects_instance(obs_data_t* settings, obs_source_t* s try { kv.second = streamfx::obs::gs::effect::create(path); } catch (const std::exception& ex) { - DLOG_ERROR(ST_PREFIX "Failed to load effect '%s' (located at '%s') with error(s): %s", kv.first, - path.c_str(), ex.what()); + D_LOG_ERROR("Failed to load effect '%s' (located at '%s') with error(s): %s", kv.first, path.c_str(), + ex.what()); } } } @@ -711,18 +724,28 @@ obs_properties_t* sdf_effects_factory::get_properties2(sdf_effects_instance* dat #ifdef ENABLE_FRONTEND bool sdf_effects_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _filter_sdf_effects_factory_instance = nullptr; void streamfx::filter::sdf_effects::sdf_effects_factory::initialize() -{ +try { if (!_filter_sdf_effects_factory_instance) _filter_sdf_effects_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::sdf_effects::sdf_effects_factory::finalize() diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index 7e57d81..8a312c5 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -21,6 +21,21 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif #define ST_I18N "Filter.Shader" @@ -192,18 +207,28 @@ obs_properties_t* shader_factory::get_properties2(shader::shader_instance* data) #ifdef ENABLE_FRONTEND bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _filter_shader_factory_instance = nullptr; void streamfx::filter::shader::shader_factory::initialize() -{ +try { if (!_filter_shader_factory_instance) _filter_shader_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::filter::shader::shader_factory::finalize() diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index 9549128..a155770 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -22,6 +22,21 @@ #include #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif // OBS #ifdef _MSC_VER @@ -611,18 +626,28 @@ obs_properties_t* transform_factory::get_properties2(transform_instance* data) #ifdef ENABLE_FRONTEND bool transform_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _filter_transform_factory_instance = nullptr; void transform_factory::initialize() -{ +try { if (!_filter_transform_factory_instance) _filter_transform_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void transform_factory::finalize() diff --git a/source/filters/filter-video-superresolution.cpp b/source/filters/filter-video-superresolution.cpp index e5e0c81..0f41bf8 100644 --- a/source/filters/filter-video-superresolution.cpp +++ b/source/filters/filter-video-superresolution.cpp @@ -572,9 +572,15 @@ obs_properties_t* video_superresolution_factory::get_properties2(video_superreso #ifdef ENABLE_FRONTEND bool video_superresolution_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif @@ -594,9 +600,13 @@ bool streamfx::filter::video_superresolution::video_superresolution_factory::is_ std::shared_ptr _video_denoising_factory_instance = nullptr; void video_superresolution_factory::initialize() -{ +try { if (!_video_denoising_factory_instance) _video_denoising_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void video_superresolution_factory::finalize() diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index 0acf1e2..8a4e2fe 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -29,6 +29,21 @@ #include "obs/gs/gs-helper.hpp" #include "obs/obs-source-tracker.hpp" #include "obs/obs-tools.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif // OBS #ifdef _MSC_VER @@ -380,21 +395,34 @@ obs_properties_t* mirror_factory::get_properties2(mirror_instance* data) #ifdef ENABLE_FRONTEND bool mirror_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _source_mirror_factory_instance; void streamfx::source::mirror::mirror_factory::initialize() -{ +try { if (!_source_mirror_factory_instance) _source_mirror_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } -void streamfx::source::mirror::mirror_factory::finalize() {} +void streamfx::source::mirror::mirror_factory::finalize() +{ + _source_mirror_factory_instance.reset(); +} std::shared_ptr streamfx::source::mirror::mirror_factory::get() { diff --git a/source/sources/source-shader.cpp b/source/sources/source-shader.cpp index b6f8ca9..15c64e7 100644 --- a/source/sources/source-shader.cpp +++ b/source/sources/source-shader.cpp @@ -21,6 +21,21 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif #define ST_I18N "Source.Shader" @@ -145,18 +160,28 @@ obs_properties_t* shader_factory::get_properties2(shader_instance* data) #ifdef ENABLE_FRONTEND bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _source_shader_factory_instance = nullptr; void streamfx::source::shader::shader_factory::initialize() -{ +try { if (!_source_shader_factory_instance) _source_shader_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::source::shader::shader_factory::finalize() diff --git a/source/transitions/transition-shader.cpp b/source/transitions/transition-shader.cpp index 83a3e62..00c5de5 100644 --- a/source/transitions/transition-shader.cpp +++ b/source/transitions/transition-shader.cpp @@ -21,6 +21,21 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" +#include "util/util-logging.hpp" + +#ifdef _DEBUG +#define ST_PREFIX "<%s> " +#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__) +#else +#define ST_PREFIX " " +#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__) +#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__) +#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__) +#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) +#endif #define ST_I18N "Transition.Shader" @@ -166,18 +181,28 @@ obs_properties_t* shader_factory::get_properties2(shader::shader_instance* data) #ifdef ENABLE_FRONTEND bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) -{ +try { streamfx::open_url(HELP_URL); return false; +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to open manual due to error: %s", ex.what()); + return false; +} catch (...) { + D_LOG_ERROR("Failed to open manual due to unknown error.", ""); + return false; } #endif std::shared_ptr _transition_shader_factory_instance = nullptr; void streamfx::transition::shader::shader_factory::initialize() -{ +try { if (!_transition_shader_factory_instance) _transition_shader_factory_instance = std::make_shared(); +} catch (const std::exception& ex) { + D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); +} catch (...) { + D_LOG_ERROR("Failed to initialize due to unknown error.", ""); } void streamfx::transition::shader::shader_factory::finalize()