Skip to content

Commit cfe8450

Browse files
committed
Prevent crash when start/stop/start recording
1 parent 79b36d2 commit cfe8450

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

Source/Processors/RecordNode/BinaryFormat/NpyFile.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,27 +156,30 @@ void NpyFile::writeHeader(const Array<NpyType>& typeList)
156156

157157
void NpyFile::updateHeader()
158158
{
159-
// overwrite the shape part of the header - even without explicitly calling
160-
// m_file->flush(), overwriting seems to trigger a flush to disk,
161-
// while appending to end of file does not
162-
int64 currentPos = m_file->getPosition(); // returns int64, necessary for big files
163-
if (m_file->setPosition(m_shapePos))
159+
if (m_file != NULL)
164160
{
165-
String newShape = getShapeString();
166-
if (m_shapePos + newShape.getNumBytesAsUTF8() + 1 > m_headerLen) // +1 for newline
161+
// overwrite the shape part of the header - even without explicitly calling
162+
// m_file->flush(), overwriting seems to trigger a flush to disk,
163+
// while appending to end of file does not
164+
int64 currentPos = m_file->getPosition(); // returns int64, necessary for big files
165+
if (m_file->setPosition(m_shapePos))
167166
{
168-
std::cerr << "Error. Header has grown too big to update in-place " << std::endl;
167+
String newShape = getShapeString();
168+
if (m_shapePos + newShape.getNumBytesAsUTF8() + 1 > m_headerLen) // +1 for newline
169+
{
170+
std::cerr << "Error. Header has grown too big to update in-place " << std::endl;
171+
}
172+
m_file->write(newShape.toUTF8(), newShape.getNumBytesAsUTF8());
173+
m_file->flush(); // not necessary, already flushed due to overwrite? do it anyway
174+
m_file->setPosition(currentPos); // restore position to end of file
175+
}
176+
else
177+
{
178+
std::cerr << "Error. Unable to seek to update file header"
179+
<< m_file->getFile().getFullPathName() << std::endl;
169180
}
170-
m_file->write(newShape.toUTF8(), newShape.getNumBytesAsUTF8());
171-
m_file->flush(); // not necessary, already flushed due to overwrite? do it anyway
172-
m_file->setPosition(currentPos); // restore position to end of file
173-
}
174-
else
175-
{
176-
std::cerr << "Error. Unable to seek to update file header"
177-
<< m_file->getFile().getFullPathName() << std::endl;
178181
}
179-
182+
180183
}
181184

182185
NpyFile::~NpyFile()

0 commit comments

Comments
 (0)