Assert that demo recording/playback are properly started/stopped

Add assertions to check that demo recording/playback is not started when already running.

Add assertions to check that demo recording/playback is stopped before the respective demo recorder/player is destroyed.
This commit is contained in:
Robert Müller 2023-10-10 21:44:32 +02:00
parent 543e63ee71
commit a0b708a0b2
3 changed files with 18 additions and 8 deletions

View file

@ -94,7 +94,7 @@ public:
TICK_NEXT, // go to the next tick
};
~IDemoPlayer() {}
virtual ~IDemoPlayer() {}
virtual void SetSpeed(float Speed) = 0;
virtual void SetSpeedIndex(int SpeedIndex) = 0;
virtual void AdjustSpeedIndex(int Offset) = 0;
@ -115,7 +115,7 @@ class IDemoRecorder : public IInterface
{
MACRO_INTERFACE("demorecorder", 0)
public:
~IDemoRecorder() {}
virtual ~IDemoRecorder() {}
virtual bool IsRecording() const = 0;
virtual int Stop() = 0;
virtual int Length() const = 0;

View file

@ -43,9 +43,16 @@ CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool NoMapDat
m_NoMapData = NoMapData;
}
CDemoRecorder::~CDemoRecorder()
{
dbg_assert(m_File == 0, "Demo recorder was not stopped");
}
// Record
int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, SHA256_DIGEST *pSha256, unsigned Crc, const char *pType, unsigned MapSize, unsigned char *pMapData, IOHANDLE MapFile, DEMOFUNC_FILTER pfnFilter, void *pUser)
{
dbg_assert(m_File == 0, "Demo recorder already recording");
m_pfnFilter = pfnFilter;
m_pUser = pUser;
@ -64,12 +71,6 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
return -1;
}
if(m_File)
{
io_close(DemoFile);
return -1;
}
bool CloseMapFile = false;
if(MapFile)
@ -407,6 +408,11 @@ CDemoPlayer::CDemoPlayer(class CSnapshotDelta *pSnapshotDelta)
Construct(pSnapshotDelta);
}
CDemoPlayer::~CDemoPlayer()
{
dbg_assert(m_File == 0, "Demo player not stopped");
}
void CDemoPlayer::Construct(class CSnapshotDelta *pSnapshotDelta)
{
m_File = 0;
@ -718,6 +724,8 @@ void CDemoPlayer::Unpause()
int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType)
{
dbg_assert(m_File == 0, "Demo player already playing");
m_pConsole = pConsole;
m_File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
if(!m_File)

View file

@ -37,6 +37,7 @@ class CDemoRecorder : public IDemoRecorder
public:
CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool NoMapData = false);
CDemoRecorder() {}
~CDemoRecorder() override;
int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, SHA256_DIGEST *pSha256, unsigned MapCrc, const char *pType, unsigned MapSize, unsigned char *pMapData, IOHANDLE MapFile = nullptr, DEMOFUNC_FILTER pfnFilter = nullptr, void *pUser = nullptr);
int Stop() override;
@ -126,6 +127,7 @@ private:
public:
CDemoPlayer(class CSnapshotDelta *pSnapshotDelta);
CDemoPlayer(class CSnapshotDelta *pSnapshotDelta, TUpdateIntraTimesFunc &&UpdateIntraTimesFunc);
~CDemoPlayer() override;
void Construct(class CSnapshotDelta *pSnapshotDelta);