From a9b1a972f476494b65890e662924c2efc2b78c8d Mon Sep 17 00:00:00 2001 From: Rickhu Date: Mon, 24 Jun 2024 13:06:55 +0800 Subject: [PATCH] bugfix: Prevent image loading crash when actual channel is not three Fix an issue in the stbi_loadf and stbi_load functions where the last parameter was incorrectly set to three. This caused the "data" array to always have three channels, rather than the expected "c" channels. --- src/ResourceLayer/File/Image.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResourceLayer/File/Image.cpp b/src/ResourceLayer/File/Image.cpp index 6283ce6a..97ea4cbd 100644 --- a/src/ResourceLayer/File/Image.cpp +++ b/src/ResourceLayer/File/Image.cpp @@ -25,14 +25,14 @@ Image::Image(const std::string &path, ImageLoadMode ilm) { isHdr = stbi_is_hdr(path.c_str()); int w, h, c; if (isHdr) { - float *data = stbi_loadf(path.c_str(), &w, &h, &c, 3); + float *data = stbi_loadf(path.c_str(), &w, &h, &c, 0); imageRawData = new float[w * h * c]; std::memcpy(imageRawData, data, w * h * c * sizeof(float)); free(data); } else // todo: bw mode { - unsigned char *data = stbi_load(path.c_str(), &w, &h, &c, 3); + unsigned char *data = stbi_load(path.c_str(), &w, &h, &c, 0); if (!data) { std::cout << "Fail to load image " << path << std::endl; return;