Try fix plugin reload while loading.

This commit is contained in:
Martín Lucas Golini
2023-10-26 11:05:13 -03:00
parent 6f5c45a408
commit d98023d9aa
7 changed files with 42 additions and 16 deletions

View File

@@ -449,7 +449,12 @@ UIWindow* UIPluginManager::New( UISceneNode* sceneNode, PluginManager* manager,
}
Plugin::Plugin( PluginManager* manager ) :
mManager( manager ), mThreadPool( manager->getThreadPool() ) {}
mManager( manager ),
mThreadPool( manager->getThreadPool() ),
mReady( false ), // All plugins will start as not ready until proved the contrary
mLoading( true ) // All plugins will start as loading until the load is complete, this is to
// avoid concurrency issues
{}
void Plugin::subscribeFileSystemListener() {
if ( mFileSystemListenerCb != 0 || mManager->getFileSystemListener() == nullptr )
@@ -461,12 +466,12 @@ void Plugin::subscribeFileSystemListener() {
[this]( const FileEvent& ev, const FileInfo& file ) {
if ( ev.type != FileSystemEventType::Modified )
return;
if ( !mShuttingDown && !mLoading && file.getFilepath() == mConfigPath &&
if ( !mShuttingDown && !isLoading() && file.getFilepath() == mConfigPath &&
file.getModificationTime() != mConfigFileInfo.getModificationTime() ) {
std::string fileContents;
FileSystem::fileGet( file.getFilepath(), fileContents );
if ( getConfigFileHash() != String::hash( fileContents ) ) {
if ( mManager->isPluginReloadEnabled() ) {
if ( mManager->isPluginReloadEnabled() && !isLoading() && isReady() ) {
mConfigFileInfo = file;
mManager->getFileSystemListener()->removeListener( mFileSystemListenerCb );
mFileSystemListenerCb = 0;
@@ -494,6 +499,10 @@ bool Plugin::isReady() const {
return mReady;
}
bool Plugin::isLoading() const {
return mLoading;
}
bool Plugin::isShuttingDown() const {
return mShuttingDown;
}