Skip to content

Commit

Permalink
ImageCache should not close IOProxy-based files to stay in file limit…
Browse files Browse the repository at this point in the history
…s (2666)

The thing about IOProxy is, once closed, it can't be reopened. So it's
important that if an IOProxy-based file is in the IC, its ImageInput
should not be reclaimed by closing it (and that might not help the
file handle count anyway, since the main use of an IOProxy under those
circumstances is probably to read an image from memory).

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Aug 11, 2020
1 parent a6345e0 commit ecbeda6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libtexture/imagecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ ImageCacheFile::ImageCacheFile(ImageCacheImpl& imagecache,
|| m_filename.find("<u>") != m_filename.npos
|| m_filename.find("<v>") != m_filename.npos)
&& !Filesystem::exists(m_filename);

// If the config has an IOProxy, remember that we should never actually
// release() it, because the proxy can't be reopened.
if (config && config->find_attribute("oiio:ioproxy", TypeDesc::PTR))
m_allow_release = false;
}


Expand Down Expand Up @@ -1060,7 +1065,7 @@ ImageCacheFile::release()
m_mutex_wait_time += input_mutex_timer();
if (m_used)
m_used = false;
else
else if (m_allow_release)
close();
}

Expand Down
1 change: 1 addition & 0 deletions src/libtexture/imagecache_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class OIIO_API ImageCacheFile : public RefCnt {
ustring m_filename; ///< Filename
bool m_used; ///< Recently used (in the LRU sense)
bool m_broken; ///< has errors; can't be used properly
bool m_allow_release = true; ///< Allow the file to release()?
std::string m_broken_message; ///< Error message for why it's broken
std::shared_ptr<ImageInput> m_input; ///< Open ImageInput, NULL if closed
// Note that m_input, the shared pointer itself, is NOT safe to
Expand Down

0 comments on commit ecbeda6

Please sign in to comment.