Skip to content

Commit

Permalink
#5429: Fix a module initialisation order problem - if the eclass modu…
Browse files Browse the repository at this point in the history
…le gets initialised before the VFS is initialised, no files are parsed.
  • Loading branch information
codereader committed Nov 22, 2020
1 parent 3e480af commit 91de737
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/ifilesystem.h
Expand Up @@ -143,10 +143,16 @@ class VirtualFileSystem :
// Initialises the filesystem using the given search order.
virtual void initialise(const SearchPaths& vfsSearchPaths, const ExtensionSet& allowedArchiveExtensions) = 0;

// Returns true if the filesystem has already been initialised
virtual bool isInitialised() const = 0;

/// \brief Shuts down the filesystem.
virtual void shutdown() = 0;

// greebo: Adds/removes observers to/from the VFS
// Observers should also check isInitialised() after adding themselves
// since the VFS might have been initialised already. Calling addObserver()
// won't call onFileSystemInitialise() if that's the case.
virtual void addObserver(Observer& observer) = 0;
virtual void removeObserver(Observer& observer) = 0;

Expand Down
6 changes: 5 additions & 1 deletion radiantcore/eclass/EClassManager.cpp
Expand Up @@ -290,7 +290,11 @@ void EClassManager::initialiseModule(const IApplicationContext& ctx)
rMessage() << "EntityClassDoom3::initialiseModule called." << std::endl;

GlobalFileSystem().addObserver(*this);
realise();

if (GlobalFileSystem().isInitialised())
{
realise();
}

GlobalCommandSystem().addCommand("ReloadDefs", std::bind(&EClassManager::reloadDefsCmd, this, std::placeholders::_1));
}
Expand Down
7 changes: 6 additions & 1 deletion radiantcore/vfs/Doom3FileSystem.cpp
Expand Up @@ -304,7 +304,7 @@ void Doom3FileSystem::initialise(const SearchPaths& vfsSearchPaths, const Extens
return;
}

if (!_vfsSearchPaths.empty())
if (isInitialised())
{
// We've been initialised with some paths already, shutdown first
shutdown();
Expand Down Expand Up @@ -336,6 +336,11 @@ void Doom3FileSystem::initialise(const SearchPaths& vfsSearchPaths, const Extens
}
}

bool Doom3FileSystem::isInitialised() const
{
return !_vfsSearchPaths.empty();
}

void Doom3FileSystem::shutdown()
{
for (Observer* observer : _observers)
Expand Down
1 change: 1 addition & 0 deletions radiantcore/vfs/Doom3FileSystem.h
Expand Up @@ -32,6 +32,7 @@ class Doom3FileSystem :

public:
void initialise(const SearchPaths& vfsSearchPaths, const ExtensionSet& allowedExtensions) override;
bool isInitialised() const override;
void shutdown() override;

int getFileCount(const std::string& filename) override;
Expand Down

0 comments on commit 91de737

Please sign in to comment.