[Bf-blender-cvs] [b23a5dbcad0] temp-sybren-alembic-filestreams: Alembic: removed our own file streams for reading.
Sybren A. Stüvel
noreply at git.blender.org
Mon Jul 3 14:34:15 CEST 2017
Commit: b23a5dbcad0fdb4027ad87a7240b44edf23becd9
Author: Sybren A. Stüvel
Date: Mon Jul 3 12:23:00 2017 +0200
Branches: temp-sybren-alembic-filestreams
https://developer.blender.org/rBb23a5dbcad0fdb4027ad87a7240b44edf23becd9
Alembic: removed our own file streams for reading.
This caused problems with some streams being reused after closing.
Now I just pass the filename to the Alembic library and let that
handle with actually opening & closing the files.
===================================================================
M source/blender/alembic/intern/abc_archive.cc
M source/blender/alembic/intern/abc_archive.h
===================================================================
diff --git a/source/blender/alembic/intern/abc_archive.cc b/source/blender/alembic/intern/abc_archive.cc
index bd16196cb78..34e8c1a918a 100644
--- a/source/blender/alembic/intern/abc_archive.cc
+++ b/source/blender/alembic/intern/abc_archive.cc
@@ -41,17 +41,24 @@ using Alembic::Abc::kWrapExisting;
using Alembic::Abc::OArchive;
static IArchive open_archive(const std::string &filename,
- const std::vector<std::istream *> &input_streams,
bool &is_hdf5)
{
+ Alembic::AbcCoreAbstract::ReadArraySampleCachePtr cache_ptr;
is_hdf5 = false;
- try {
- Alembic::AbcCoreOgawa::ReadArchive archive_reader(input_streams);
+#ifdef WIN32
+ UTF16_ENCODE(filename);
+ const std::wstring open_filename(filename_16);
+ UTF16_UN_ENCODE(filename);
+#else
+ const std::string &open_filename = filename;
+#endif
- return IArchive(archive_reader(filename),
- kWrapExisting,
- ErrorHandler::kThrowPolicy);
+ try {
+ IArchive archive(Alembic::AbcCoreOgawa::ReadArchive(),
+ open_filename.c_str(),
+ ErrorHandler::kThrowPolicy, cache_ptr);
+ return archive;
}
catch (const Exception &e) {
std::cerr << e.what() << '\n';
@@ -59,11 +66,9 @@ static IArchive open_archive(const std::string &filename,
#ifdef WITH_ALEMBIC_HDF5
try {
is_hdf5 = true;
- Alembic::AbcCoreAbstract::ReadArraySampleCachePtr cache_ptr;
-
return IArchive(Alembic::AbcCoreHDF5::ReadArchive(),
- filename.c_str(), ErrorHandler::kThrowPolicy,
- cache_ptr);
+ open_filename.c_str(),
+ ErrorHandler::kThrowPolicy, cache_ptr);
}
catch (const Exception &) {
std::cerr << e.what() << '\n';
@@ -72,19 +77,19 @@ static IArchive open_archive(const std::string &filename,
#else
/* Inspect the file to see whether it's really a HDF5 file. */
char header[4]; /* char(0x89) + "HDF" */
- std::ifstream the_file(filename.c_str(), std::ios::in | std::ios::binary);
+ std::ifstream the_file(open_filename.c_str(), std::ios::in | std::ios::binary);
if (!the_file) {
- std::cerr << "Unable to open " << filename << std::endl;
+ std::cerr << "Unable to open " << open_filename << std::endl;
}
else if (!the_file.read(header, sizeof(header))) {
- std::cerr << "Unable to read from " << filename << std::endl;
+ std::cerr << "Unable to read from " << open_filename << std::endl;
}
else if (strncmp(header + 1, "HDF", 3)) {
- std::cerr << filename << " has an unknown file format, unable to read." << std::endl;
+ std::cerr << open_filename << " has an unknown file format, unable to read." << std::endl;
}
else {
is_hdf5 = true;
- std::cerr << filename << " is in the obsolete HDF5 format, unable to read." << std::endl;
+ std::cerr << open_filename << " is in the obsolete HDF5 format, unable to read." << std::endl;
}
if (the_file.is_open()) {
@@ -100,24 +105,7 @@ static IArchive open_archive(const std::string &filename,
ArchiveReader::ArchiveReader(const char *filename)
{
-#ifdef WIN32
- UTF16_ENCODE(filename);
- std::wstring wstr(filename_16);
- m_infile.open(wstr.c_str(), std::ios::in | std::ios::binary);
- UTF16_UN_ENCODE(filename);
-#else
- m_infile.open(filename, std::ios::in | std::ios::binary);
-#endif
-
- m_streams.push_back(&m_infile);
-
- m_archive = open_archive(filename, m_streams, m_is_hdf5);
-
- /* We can't open an HDF5 file from a stream, so close it. */
- if (m_is_hdf5) {
- m_infile.close();
- m_streams.clear();
- }
+ m_archive = open_archive(filename, m_is_hdf5);
}
bool ArchiveReader::is_hdf5() const
diff --git a/source/blender/alembic/intern/abc_archive.h b/source/blender/alembic/intern/abc_archive.h
index 84309fbc9df..2454ef2442b 100644
--- a/source/blender/alembic/intern/abc_archive.h
+++ b/source/blender/alembic/intern/abc_archive.h
@@ -41,9 +41,8 @@
*/
class ArchiveReader {
+ std::string filename;
Alembic::Abc::IArchive m_archive;
- std::ifstream m_infile;
- std::vector<std::istream *> m_streams;
bool m_is_hdf5;
public:
More information about the Bf-blender-cvs
mailing list