Fix of recent GCode / GCodeProcessor refactoring: Don't close a FILE

twice.
This commit is contained in:
Vojtech Bubnik 2021-09-07 17:58:06 +02:00
parent 152e236dda
commit 0da0a7b2a0
2 changed files with 23 additions and 4 deletions

View file

@ -2642,9 +2642,23 @@ std::string GCode::extrude_support(const ExtrusionEntityCollection &support_fill
return gcode;
}
bool GCode::GCodeOutputStream::is_error() const { return ::ferror(f); }
void GCode::GCodeOutputStream::flush() { ::fflush(f); }
void GCode::GCodeOutputStream::close() { if (f) ::fclose(f); }
bool GCode::GCodeOutputStream::is_error() const
{
return ::ferror(this->f);
}
void GCode::GCodeOutputStream::flush()
{
::fflush(this->f);
}
void GCode::GCodeOutputStream::close()
{
if (this->f) {
::fclose(this->f);
this->f = nullptr;
}
}
void GCode::GCodeOutputStream::write(const char *what)
{

View file

@ -350,7 +350,12 @@ void GCodeProcessor::TimeProcessor::reset()
struct FilePtr {
FilePtr(FILE *f) : f(f) {}
~FilePtr() { this->close(); }
void close() { if (f) ::fclose(f); }
void close() {
if (this->f) {
::fclose(this->f);
this->f = nullptr;
}
}
FILE* f = nullptr;
};