From 4b364865a11eee5f239c757aee1d7655b9e3edf0 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 5 Nov 2017 21:31:05 +0100 Subject: [PATCH] gs-effect: Allow empty effect and check errorMessage validity --- source/gs-effect.cpp | 18 ++++++++++++++---- source/gs-effect.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/source/gs-effect.cpp b/source/gs-effect.cpp index 4b08e297..3ba0663f 100644 --- a/source/gs-effect.cpp +++ b/source/gs-effect.cpp @@ -26,13 +26,20 @@ extern "C" { #pragma warning( pop ) } +GS::Effect::Effect() { + m_effect = nullptr; +} + GS::Effect::Effect(std::string file) { obs_enter_graphics(); char* errorMessage = nullptr; m_effect = gs_effect_create_from_file(file.c_str(), &errorMessage); if (!m_effect || errorMessage) { - std::string error(errorMessage); - bfree((void*)errorMessage); + std::string error = "Generic Error"; + if (errorMessage) { + error = std::string(errorMessage); + bfree((void*)errorMessage); + } obs_leave_graphics(); throw std::runtime_error(error); } @@ -44,8 +51,11 @@ GS::Effect::Effect(std::string code, std::string name) { char* errorMessage = nullptr; m_effect = gs_effect_create(code.c_str(), name.c_str(), &errorMessage); if (!m_effect || errorMessage) { - std::string error(errorMessage); - bfree((void*)errorMessage); + std::string error = "Generic Error"; + if (errorMessage) { + error = std::string(errorMessage); + bfree((void*)errorMessage); + } obs_leave_graphics(); throw std::runtime_error(error); } diff --git a/source/gs-effect.h b/source/gs-effect.h index 9b2349b0..2878e436 100644 --- a/source/gs-effect.h +++ b/source/gs-effect.h @@ -84,6 +84,7 @@ namespace GS { class Effect { public: + Effect(); Effect(std::string file); Effect(std::string code, std::string name); virtual ~Effect();