1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

fix_crash_loading_frames_from_def

This commit is contained in:
MichalZr6
2024-11-27 23:07:45 +01:00
parent 132500b292
commit 5fc61df717
6 changed files with 61 additions and 12 deletions

View File

@@ -239,7 +239,7 @@ std::shared_ptr<const ISharedImage> RenderHandler::loadImageImpl(const ImageLoca
std::shared_ptr<const ISharedImage> RenderHandler::loadImageFromFileUncached(const ImageLocator & locator)
{
if (locator.image)
if(locator.image)
{
// TODO: create EmptySharedImage class that will be instantiated if image does not exists or fails to load
return std::make_shared<SDLImageShared>(*locator.image, locator.preScaledFactor);
@@ -258,7 +258,14 @@ std::shared_ptr<const ISharedImage> RenderHandler::loadImageFromFileUncached(con
preScaledFactor = 1;
defFile = getAnimationFile(AnimationPath::builtin(tmpPath));
}
return std::make_shared<SDLImageShared>(defFile.get(), locator.defFrame, locator.defGroup, preScaledFactor);
if(defFile->hasFrame(locator.defFrame, locator.defGroup))
return std::make_shared<SDLImageShared>(defFile.get(), locator.defFrame, locator.defGroup, preScaledFactor);
else
{
logGlobal->error("Frame %d in group %d not found in file: %s",
locator.defFrame, locator.defGroup, locator.defFile->getName().c_str());
return std::make_shared<SDLEmptyImageShared>();
}
}
throw std::runtime_error("Invalid image locator received!");