Skip to content

Commit

Permalink
Use a non-local(!!!) mutex to protect the Ptex::PtexCache variable
Browse files Browse the repository at this point in the history
Via @Hyiker, fixes #409.
  • Loading branch information
mmp committed Jan 25, 2024
1 parent eb1d4ca commit 51e68cc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pbrt/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ SpectrumDirectionMixTexture *SpectrumDirectionMixTexture::Create(
parameters.GetSpectrumTexture("tex2", one, spectrumType, alloc), dir);
}

static std::mutex ptexMutex;
static Ptex::PtexCache *cache;

STAT_COUNTER("Texture/Ptex lookups", nLookups);
Expand All @@ -595,8 +596,7 @@ struct : public PtexErrorHandler {
PtexTextureBase::PtexTextureBase(const std::string &filename, ColorEncoding encoding,
Float scale)
: filename(filename), encoding(encoding), scale(scale) {
std::mutex mutex;
mutex.lock();
ptexMutex.lock();
if (!cache) {
int maxFiles = 100;
size_t maxMem = 1ull << 32; // 4GB
Expand All @@ -606,7 +606,7 @@ PtexTextureBase::PtexTextureBase(const std::string &filename, ColorEncoding enco
&errorHandler);
// TODO? cache->setSearchPath(...);
}
mutex.unlock();
ptexMutex.unlock();

// Issue an error if the texture doesn't exist or has an unsupported
// number of channels.
Expand Down

0 comments on commit 51e68cc

Please sign in to comment.