gs-effect: Allow empty effect and check errorMessage validity

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2017-11-05 21:31:05 +01:00
parent fc02f3fdad
commit 4b364865a1
2 changed files with 15 additions and 4 deletions

View file

@ -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);
}

View file

@ -84,6 +84,7 @@ namespace GS {
class Effect {
public:
Effect();
Effect(std::string file);
Effect(std::string code, std::string name);
virtual ~Effect();