mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-11 06:15:05 +00:00
gfx-shader: Fix startup and select crash if file is missing
This commit is contained in:
parent
a3b1fc0b2e
commit
9696f836e0
1 changed files with 24 additions and 15 deletions
|
@ -46,19 +46,25 @@ gfx::shader::shader::shader(obs_source_t* self, shader_mode mode)
|
||||||
gfx::shader::shader::~shader() {}
|
gfx::shader::shader::~shader() {}
|
||||||
|
|
||||||
bool gfx::shader::shader::is_shader_different(const std::filesystem::path& file)
|
bool gfx::shader::shader::is_shader_different(const std::filesystem::path& file)
|
||||||
{
|
try {
|
||||||
// Check if the file name differs.
|
if (std::filesystem::exists(file)) {
|
||||||
if (file != _shader_file)
|
// Check if the file name differs.
|
||||||
return true;
|
if (file != _shader_file)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Is the file write time different?
|
if (std::filesystem::exists(_shader_file)) {
|
||||||
if (std::filesystem::last_write_time(_shader_file) != _shader_file_mt)
|
// Is the file write time different?
|
||||||
return true;
|
if (std::filesystem::last_write_time(_shader_file) != _shader_file_mt)
|
||||||
|
return true;
|
||||||
|
|
||||||
// Is the file size different?
|
// Is the file size different?
|
||||||
if (std::filesystem::file_size(_shader_file) != _shader_file_sz)
|
if (std::filesystem::file_size(_shader_file) != _shader_file_sz)
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} catch (const std::exception&) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,19 +80,22 @@ bool gfx::shader::shader::is_technique_different(const std::string& tech)
|
||||||
bool gfx::shader::shader::load_shader(const std::filesystem::path& file, const std::string& tech, bool& shader_dirty,
|
bool gfx::shader::shader::load_shader(const std::filesystem::path& file, const std::string& tech, bool& shader_dirty,
|
||||||
bool& param_dirty)
|
bool& param_dirty)
|
||||||
{
|
{
|
||||||
|
if (!std::filesystem::exists(file))
|
||||||
|
return false;
|
||||||
|
|
||||||
shader_dirty = is_shader_different(file);
|
shader_dirty = is_shader_different(file);
|
||||||
param_dirty = is_technique_different(tech) || shader_dirty;
|
param_dirty = is_technique_different(tech) || shader_dirty;
|
||||||
|
|
||||||
if (shader_dirty) {
|
if (shader_dirty) {
|
||||||
try {
|
try {
|
||||||
_shader = gs::effect(file);
|
_shader = gs::effect(file);
|
||||||
|
_shader_file = file;
|
||||||
|
_shader_file_mt = std::filesystem::last_write_time(file);
|
||||||
|
_shader_file_sz = std::filesystem::file_size(file);
|
||||||
|
_shader_file_tick = 0;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_shader_file = file;
|
|
||||||
_shader_file_mt = std::filesystem::last_write_time(file);
|
|
||||||
_shader_file_sz = std::filesystem::file_size(file);
|
|
||||||
_shader_file_tick = 0;
|
|
||||||
}
|
}
|
||||||
if (param_dirty) {
|
if (param_dirty) {
|
||||||
auto settings =
|
auto settings =
|
||||||
|
|
Loading…
Reference in a new issue