Skip to content

Commit

Permalink
RenderPlatform effect recompilation crash fixes.
Browse files Browse the repository at this point in the history
RenderPlatform::CreateEffect() adds the recompiled effect to the effect list.
RenderPlatform::GetEffect() check the recompiled effects.
  • Loading branch information
AndrewRichards-Code committed Oct 29, 2024
1 parent 018425f commit 8bd33dd
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions CrossPlatform/RenderPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void RenderPlatform::ScheduleRecompileEffects(const std::vector<std::string> &ef
{
found = true;
break;
}
}
}

if (!found)
Expand Down Expand Up @@ -2025,17 +2025,20 @@ void RenderPlatform::Destroy(Effect *&e)

Effect *RenderPlatform::CreateEffect(const char *filename_utf8, bool checkRecompileShaders)
{
std::string fn(filename_utf8);

//Check if the effect in being recompiled
if (checkRecompileShaders)
{
std::lock_guard recompileEffectFutureGuard(recompileEffectFutureMutex);
const auto &it = effectsToCompileFutures.find(std::string(filename_utf8));
const auto &it = effectsToCompileFutures.find(fn);
if (it != effectsToCompileFutures.end())
{
if (it->second.valid())
{
Effect *e = it->second.get().newEffect;
effectsToCompileFutures.erase(it);
effects[fn] = e;
return e;
}
else
Expand All @@ -2046,7 +2049,6 @@ Effect *RenderPlatform::CreateEffect(const char *filename_utf8, bool checkRecomp
}

//Else, load as normal
std::string fn(filename_utf8);
crossplatform::Effect *e=CreateEffect();
effects[fn] = e;
e->SetName(filename_utf8);
Expand All @@ -2061,6 +2063,26 @@ Effect *RenderPlatform::CreateEffect(const char *filename_utf8, bool checkRecomp

Effect* RenderPlatform::GetEffect(const char* filename_utf8)
{
std::string fn(filename_utf8);

// Check if the effect in being recompiled
std::lock_guard recompileEffectFutureGuard(recompileEffectFutureMutex);
const auto &it = effectsToCompileFutures.find(fn);
if (it != effectsToCompileFutures.end())
{
if (it->second.valid())
{
Effect *e = it->second.get().newEffect;
effectsToCompileFutures.erase(it);
effects[fn] = e;
return e;
}
else
{
effectsToCompileFutures.erase(it);
}
}

auto i = effects.find(filename_utf8);
if (i == effects.end())
return nullptr;
Expand Down

0 comments on commit 8bd33dd

Please sign in to comment.