Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libs/s25main/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ bool Replay::StopRecording()
isRecording_ = false;
file_.Close();

// Remove empty replay recordings. They are mostly produced when a game is aborted
// during startup, for example after an early script error.
if(lastGF_ == 0)
{
boost::system::error_code ec;
boost::filesystem::remove(filepath_, ec);
return !ec;
}

BinaryFile file;
if(!file.Open(filepath_, OpenFileMode::Read))
return false;
Expand Down
20 changes: 20 additions & 0 deletions tests/s25Main/integration/testSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,26 @@ struct ReplayMapFixture
}
};

BOOST_FIXTURE_TEST_CASE(EmptyReplayRecordingIsRemoved, ReplayMapFixture)
{
Replay replay;
for(const BasePlayerInfo& player : players)
replay.AddPlayer(player);
replay.ggs.speed = GameSpeed::VeryFast;

TmpFile tmpFile(".rpl");
BOOST_TEST_REQUIRE(tmpFile.isValid());
tmpFile.close();
bfs::remove(tmpFile.filePath);

BOOST_TEST_REQUIRE(replay.StartRecording(tmpFile.filePath, map, 42));
BOOST_TEST_REQUIRE(replay.IsRecording());
BOOST_TEST(replay.GetLastGF() == 0u);

BOOST_TEST_REQUIRE(replay.StopRecording());
BOOST_TEST_REQUIRE(!replay.IsRecording());
BOOST_TEST(!bfs::exists(tmpFile.filePath));
}
BOOST_FIXTURE_TEST_CASE(ReplayWithMap, ReplayMapFixture)
{
Replay replay;
Expand Down