Skip to content

Commit

Permalink
Fix TxFileStorage initialization when cache compression disabled.
Browse files Browse the repository at this point in the history
Fixed Textures do not load from uncompressed HTS files #2120
  • Loading branch information
gonetz committed Nov 4, 2019
1 parent f3b83d2 commit 09764fe
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/GLideNHQ/TxCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TxCacheImpl
class TxMemoryCache : public TxCacheImpl
{
public:
TxMemoryCache(uint32 & _options, uint64 cacheLimit, dispInfoFuncExt callback);
TxMemoryCache(uint32 _options, uint64 cacheLimit, dispInfoFuncExt callback);
~TxMemoryCache();

bool add(Checksum checksum, GHQTexInfo *info, int dataSize = 0) override;
Expand Down Expand Up @@ -103,7 +103,7 @@ class TxMemoryCache : public TxCacheImpl
uint32 _gzdestLen = 0;
};

TxMemoryCache::TxMemoryCache(uint32 & options,
TxMemoryCache::TxMemoryCache(uint32 options,
uint64 cacheLimit,
dispInfoFuncExt callback)
: _options(options)
Expand Down Expand Up @@ -481,7 +481,7 @@ void TxMemoryCache::clear()
class TxFileStorage : public TxCacheImpl
{
public:
TxFileStorage(uint32 & _options, const wchar_t *cachePath, dispInfoFuncExt callback);
TxFileStorage(uint32 _options, const wchar_t *cachePath, dispInfoFuncExt callback);
~TxFileStorage() = default;

bool add(Checksum checksum, GHQTexInfo *info, int dataSize = 0) override;
Expand Down Expand Up @@ -531,7 +531,7 @@ class TxFileStorage : public TxCacheImpl
const int TxFileStorage::_fakeConfig = -1;
const int64 TxFileStorage::_initialPos = sizeof(int64) + sizeof(int);

TxFileStorage::TxFileStorage(uint32 & options,
TxFileStorage::TxFileStorage(uint32 options,
const wchar_t *cachePath,
dispInfoFuncExt callback)
: _options(options)
Expand All @@ -541,19 +541,16 @@ TxFileStorage::TxFileStorage(uint32 & options,
if (cachePath)
_cachePath.assign(cachePath);

/* zlib memory buffers to (de)compress hires textures */
if (_options & (GZ_TEXCACHE | GZ_HIRESTEXCACHE)) {
_gzdest0 = TxMemBuf::getInstance()->get(0);
_gzdest1 = TxMemBuf::getInstance()->get(1);
_gzdestLen = (TxMemBuf::getInstance()->size_of(0) < TxMemBuf::getInstance()->size_of(1)) ?
TxMemBuf::getInstance()->size_of(0) : TxMemBuf::getInstance()->size_of(1);
_gzdest0 = TxMemBuf::getInstance()->get(0);
_gzdest1 = TxMemBuf::getInstance()->get(1);
_gzdestLen = (TxMemBuf::getInstance()->size_of(0) < TxMemBuf::getInstance()->size_of(1)) ?
TxMemBuf::getInstance()->size_of(0) : TxMemBuf::getInstance()->size_of(1);

if (!_gzdest0 || !_gzdest1 || !_gzdestLen) {
_options &= ~(GZ_TEXCACHE | GZ_HIRESTEXCACHE);
_gzdest0 = nullptr;
_gzdest1 = nullptr;
_gzdestLen = 0;
}
if (!_gzdest0 || !_gzdest1 || !_gzdestLen) {
_options &= ~(GZ_TEXCACHE | GZ_HIRESTEXCACHE);
_gzdest0 = nullptr;
_gzdest1 = nullptr;
_gzdestLen = 0;
}
}

Expand Down Expand Up @@ -654,6 +651,9 @@ bool TxFileStorage::readData(GHQTexInfo & info)
if (dataSize == 0)
return false;

if (_gzdest0 == nullptr)
return false;

_infile.read((char*)_gzdest0, dataSize);
if (!_infile.good())
return false;
Expand Down

0 comments on commit 09764fe

Please sign in to comment.