summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorJoshua Vandaƫle <joshua@vandaele.software>2025-11-28 18:13:46 +0100
committerJoshua Vandaƫle <joshua@vandaele.software>2025-11-29 23:54:48 +0100
commit5a6dc310c002a2d9d75cf7de6bc1a984339ef533 (patch)
treed6cee17715b28452898ea5ad2dbfb1c5b0a7f7e6 /Source/Core/InputCommon
parente8c512dfb5b26b464c70f6bb89475533d5351a94 (diff)
DITConfiguration: Prevent a crash if images fail to load
Recently came across a strange issue where Dolphin would hard crash in most games with this error: ```sh /usr/include/c++/15.2.1/optional:1165: constexpr const _Tp* std::optional<_Tp>::operator->() const [with _Tp = InputCommon::ImagePixelData]: Assertion 'this->_M_is_engaged()' failed. ``` The culprit turned out to be accessing `host_key_image` which is an `std::optional` thay may return `std::nullopt`. I'm not sure why this issue started occuring for me since I've had no issue with my Dynamic Input Textures in the past? But this fixes a crash if the image fails to load.
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/DynamicInputTextures/DITConfiguration.cpp10
-rw-r--r--Source/Core/InputCommon/ImageOperations.cpp7
2 files changed, 14 insertions, 3 deletions
diff --git a/Source/Core/InputCommon/DynamicInputTextures/DITConfiguration.cpp b/Source/Core/InputCommon/DynamicInputTextures/DITConfiguration.cpp
index cced429e81..9ccd98dbc2 100644
--- a/Source/Core/InputCommon/DynamicInputTextures/DITConfiguration.cpp
+++ b/Source/Core/InputCommon/DynamicInputTextures/DITConfiguration.cpp
@@ -150,7 +150,15 @@ void Configuration::GenerateTexture(const Common::IniFile& file,
}
else
{
- const auto host_key_image = LoadImage(m_base_path + input_image_iter->second);
+ const std::string full_image_path = m_base_path + input_image_iter->second;
+ const auto host_key_image = LoadImage(full_image_path);
+ if (!host_key_image)
+ {
+ ERROR_LOG_FMT(VIDEO,
+ "Failed to load image '{}' needed for dynamic input texture generation",
+ full_image_path);
+ continue;
+ }
for (const auto& rect : rects)
{
diff --git a/Source/Core/InputCommon/ImageOperations.cpp b/Source/Core/InputCommon/ImageOperations.cpp
index 907cb52b8d..8fa844fec1 100644
--- a/Source/Core/InputCommon/ImageOperations.cpp
+++ b/Source/Core/InputCommon/ImageOperations.cpp
@@ -45,9 +45,12 @@ void CopyImageRegion(const ImagePixelData& src, ImagePixelData& dst, const Rect&
std::optional<ImagePixelData> LoadImage(const std::string& path)
{
File::IOFile file;
- file.Open(path, "rb");
+ if (!file.Open(path, "rb"))
+ return std::nullopt;
+
Common::UniqueBuffer<u8> buffer(file.GetSize());
- file.ReadBytes(buffer.data(), file.GetSize());
+ if (!file.ReadBytes(buffer.data(), file.GetSize()))
+ return std::nullopt;
ImagePixelData image;
Common::UniqueBuffer<u8> data;