From cd6656be354de8facfaac015053e800490c555ee Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 1 Mar 2024 10:06:18 +0000 Subject: [PATCH] Fix archive Incorrect cmake directory was messing up reading from zips STB was failing to read from zips, it was failing to get the file info, something we were using as an early out, now if that files on the filepath, we use the memory read instead since stream needs to be a success to get to that point. --- Engine/source/CMakeLists.txt | 2 +- Engine/source/gfx/bitmap/gBitmap.cpp | 11 ++++++++--- Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Engine/source/CMakeLists.txt b/Engine/source/CMakeLists.txt index f1c243940..342338160 100644 --- a/Engine/source/CMakeLists.txt +++ b/Engine/source/CMakeLists.txt @@ -97,7 +97,7 @@ endif (WIN32 AND TORQUE_D3D11) # Handle core torqueAddSourceDirectories("core" "core/stream" "core/strings" "core/util" - "core/util/journal" "core/util/zip" "core/util/compressors") + "core/util/journal" "core/util/zip" "core/util/zip/compressors") # Handle GUI torqueAddSourceDirectories("gui" "gui/buttons" "gui/containers" "gui/controls" "gui/core" "gui/game" "gui/shiny" "gui/utility" "gui/3d") diff --git a/Engine/source/gfx/bitmap/gBitmap.cpp b/Engine/source/gfx/bitmap/gBitmap.cpp index 8fc0590b6..82c8b2c7f 100644 --- a/Engine/source/gfx/bitmap/gBitmap.cpp +++ b/Engine/source/gfx/bitmap/gBitmap.cpp @@ -1279,9 +1279,14 @@ template<> void *Resource::create(const Torque::Path &path) const String extension = path.getExtension(); if( !bmp->readBitmap( extension, path ) ) { - Con::errorf( "Resource::create - error reading '%s'", path.getFullPath().c_str() ); - delete bmp; - bmp = NULL; + // we can only get here if the stream was successful, so attempt to read the stream. + Con::warnf("Was unable to load as file, going to try the stream instead."); + if (!bmp->readBitmapStream(extension, stream, stream.getStreamSize())) + { + Con::errorf("Resource::create - error reading '%s'", path.getFullPath().c_str()); + delete bmp; + bmp = NULL; + } } return bmp; diff --git a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp index a5a97917a..00ef53891 100644 --- a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp +++ b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp @@ -195,6 +195,12 @@ bool sReadSTB(const Torque::Path& path, GBitmap* bitmap) if (!stbi_info(path.getFullPath().c_str(), &x, &y, &channels)) { FrameAllocator::setWaterMark(prevWaterMark); + const char* stbErr = stbi_failure_reason(); + + if (!stbErr) + stbErr = "Unknown Error!"; + + Con::errorf("STB failed to get image info: %s", stbErr); return false; } @@ -326,7 +332,7 @@ bool sReadStreamSTB(Stream& stream, GBitmap* bitmap, U32 len) stbErr = "Unknown Error!"; Con::errorf("STB failed to get image info: %s", stbErr); - return false; + Con::warnf("Going to attempt to load stream anyway."); } S32 reqCom = comp;