diff --git a/Storage/Disk/Disk.hpp b/Storage/Disk/Disk.hpp index 95e5bc4a9..c929bff3a 100644 --- a/Storage/Disk/Disk.hpp +++ b/Storage/Disk/Disk.hpp @@ -23,9 +23,7 @@ namespace Disk { class Disk { public: - virtual ~Disk() { - flush_tracks(); - } + virtual ~Disk() {} /*! @returns the number of discrete positions that this disk uses to model its complete surface area. diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 14866185f..e94df592a 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -21,7 +21,12 @@ Drive::Drive(unsigned int input_clock_rate, int revolutions_per_minute, int numb available_heads_(number_of_heads) { } +Drive::~Drive() { + if(disk_) disk_->flush_tracks(); +} + void Drive::set_disk(const std::shared_ptr &disk) { + if(disk_) disk_->flush_tracks(); disk_ = disk; has_disk_ = !!disk_; diff --git a/Storage/Disk/Drive.hpp b/Storage/Disk/Drive.hpp index 266ad7d54..7f321068c 100644 --- a/Storage/Disk/Drive.hpp +++ b/Storage/Disk/Drive.hpp @@ -24,6 +24,7 @@ namespace Disk { class Drive: public Sleeper, public TimedEventLoop { public: Drive(unsigned int input_clock_rate, int revolutions_per_minute, int number_of_heads); + ~Drive(); /*! Replaces whatever is in the drive with @c disk.