Hello,
I recently updated to Version: 29-Nov-2023, and I'm encountering the following error when I try to run it. Can you help me resolve this issue?
I am currently using Matlab2023b.
===================================================================
BST> Starting Brainstorm:
BST> =================================
BST> Version: 29-Nov-2023
BST> Compiling main interface files...
BST> Deleting old process reports...
BST> Loading configuration file...
BST> Checking internet connectivity... ok
BST> Initializing user interface...
BST> WARNING: Mutex "Brainstorm" already exists.
BST> Starting OpenGL engine... hardware
BST> Loading plugins... Error occurred while using: dir
Invalid path. The path must not contain null characters.
It seems it is related to path where the plugins are.
After getting the error, run these lines in Matlab, and paste the result in this post
% Get list of Plugins that are installed
InstPlugs = bst_plugin('GetInstalled');
% For the Installed Plugins that are Loaded at the Startup, print the Path of their logos
{InstPlugs(logical([InstPlugs.AutoLoad])).LogoFile}
In the meantime, I have upgraded to the latest version with Matlab2024a, but I am still encountering issues when running Brainstorm. The error message is as follows:
BST> Loading plugins... Error using dir
Invalid path. The path must not contain a null character.
Error in file_exist (line 34)
elseif isempty(dir(filename))
Error in bst_plugin>GetLogoFile (line 1213)
if file_exist(PlugDesc.LogoFile)
Error in bst_plugin>Load (line 1981)
LogoFile = GetLogoFile(PlugDesc);
Error in bst_plugin (line 111)
eval(macro_method);
Error in bst_startup (line 457)
bst_plugin('Load', InstPlugs(iPlug), 0);
Error in brainstorm (line 123)
bst_startup(BrainstormHomeDir, 1, BrainstormDbDir);
I then entered the code you suggested and ran Brainstorm:
% Get the list of installed plugins
InstPlugs = bst_plugin('GetInstalled');
% Print the logo paths of plugins that are automatically loaded at startup
{InstPlugs(logical([InstPlugs.AutoLoad])).LogoFile}
ans =
1×2 cell array
{'C:\Users\Jun Meditech\OneDrive - Fubi …'} {0×0 char}
Afterwards, I encountered the following error:
>> brainstorm
BST> Starting Brainstorm:
BST> =================================
BST> Version: 16-May-2024
BST> Compiling main interface files...
BST> Deleting old process reports...
BST> Loading configuration file...
BST> Checking internet connectivity... ok
BST> Initializing user interface...
BST> WARNING: Mutex "Brainstorm" already exists.
BST> Starting OpenGL engine... hardware
BST> Loading plugins... Error using dir
Invalid path. The path must not contain a null character.
Error in file_exist (line 34)
elseif isempty(dir(filename))
Error in bst_plugin>GetLogoFile (line 1213)
if file_exist(PlugDesc.LogoFile)
Error in bst_plugin>Load (line 1981)
LogoFile = GetLogoFile(PlugDesc);
Error in bst_plugin (line 111)
eval(macro_method);
Error in bst_startup (line 457)
bst_plugin('Load', InstPlugs(iPlug), 0);
Error in brainstorm (line 123)
bst_startup(BrainstormHomeDir, 1, BrainstormDbDir);
I would appreciate your assistance in resolving this issue.
I'm sharing this to help anyone who might be experiencing the same issue.
The problematic code is in the file_exist.m file.
To modify the code to work correctly in MATLAB 2024a, it's important to make the path handling and file existence checks more compatible. Specifically, using exist instead of dir and using fullfile for path creation are recommended.
Use the exist function instead of dir to check for the existence of files and directories.
Use the fullfile function to handle path creation according to the platform.
Add a section to remove null characters from the filename.
% Remove null characters from filename
filename = strrep(filename, char(0), '');
% Empty variable
if isempty(filename)
isExist = 0;
% File is a root folder: let's consider it exists
elseif isequal(filename, '/') || isequal(filename, '\')
isExist = 1;
% File does not exist: no ambiguity
elseif exist(filename, 'file') == 0 && exist(filename, 'dir') == 0
isExist = 0;
% File exists: we have to make sure it is NOT relative to the current path
else
% Check the file relative to the current Matlab folder
pwdPath = pwd;
pwdFile = fullfile(pwdPath, filename);
% If it does NOT exist: no ambiguity, file exists
if exist(pwdFile, 'file') == 0 && exist(pwdFile, 'dir') == 0
isExist = 1;
% Else: we consider that the file exists only if the current folder is a root folder
% (=> folder = folder's parent)
elseif strcmp(pwdPath, bst_fileparts(pwdPath, 1))
isExist = 1;
else
isExist = 0;
end
end
This is only a temporary fix, and I do not have the authority to modify the code permanently.
This code is for the community members who are facing the same issue as I am.
If this causes any problems, I will delete it.
Thank you @yyj108, for further exploring this issue.
I have tested this script on the recent Matlab releases including the 2024a in multiple OSs and it's working fine. About the proposed changes:
The function dir works perfectly on 2024a. The use of exist(..., 'file') is not advice, as it can return true, if there is a file with the same file name in the path.
Yes, it would be better to improve the fullpath creation
It seems that removing the null characters in the path, does not solve the problem but it just skips the file verification.
The file_exist script is used all around Brainstorm, we will thoroughly test the impact of the proposed changes.
The issue you have seems to be related to the specific path where the logo images are stored. To help finding the issue, could you revert the adhoc changes in file_exist run Brainstorm and when the error happens run this lines in the Matlab Command Window, and past the answer.
% Get the list of installed plugins
InstPlugs = bst_plugin('GetInstalled');
% Print the logo paths of plugins that are automatically loaded at startup
logoPaths = {InstPlugs(logical([InstPlugs.AutoLoad])).LogoFile};
for logoPath = logoPaths; disp(logoPath{:});end
If the printed path contains sensitive information, please shared as a direct message to me
Sure!
I entered the suggested code and it shows the following path:
C:\Users\Jun Meditech\OneDrive - Fubi Technology Co., Ltd\瑁 �\DATA\brainstorm3\doc\plugins\brainentropy_logo.png
I hope this helps.