Skip to content

Commit 478bd7b

Browse files
committed
Fix crashes if no editors are installed
interface_derived.cpp + check if there are editors and warn user if they try to create a project with none installed + null check on opening the install path to prevent crash on launch
1 parent e08c811 commit 478bd7b

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

source/interface_derived.cpp

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,20 @@ void MainFrameDerived::OnRemoveInstallPath(wxCommandEvent& event){
258258
*/
259259
void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
260260
//create a dialog and show it
261-
DialogCallback d = [&](string str, project p){
262-
//add the project
263-
this->AddProject(p);
264-
265-
//launch the process
266-
launch_process(str);
267-
};
268-
CreateProjectDialogD* dialog = new CreateProjectDialogD(this,editors,d);
269-
dialog->show();
261+
if (editors.size() > 0){
262+
DialogCallback d = [&](string str, project p){
263+
//add the project
264+
this->AddProject(p);
265+
266+
//launch the process
267+
launch_process(str);
268+
};
269+
CreateProjectDialogD* dialog = new CreateProjectDialogD(this,editors,d);
270+
dialog->show();
271+
}
272+
else{
273+
wxMessageBox("UnityHubNative could not find any Unity Editors installed on this sytem. If you have an editor installed, make sure UnityHubNative can find it by adding its location to the Install Search Paths section of the Editor Versions Tab.\n\nIf you do not have any Unity editors installed, you must use the official hub to install one before you can create a new project with UnityHubNative.","Cannot Create Project",wxOK | wxICON_ERROR);
274+
}
270275
}
271276

272277
/**
@@ -463,29 +468,31 @@ void MainFrameDerived::LoadEditorVersions(){
463468
for (string& path : installPaths){
464469
//open the folder
465470
DIR* dir = opendir(path.c_str());
466-
struct dirent *entry = readdir(dir);
467-
//loop over the contents
468-
wxArrayString a;
469-
while (entry != NULL)
470-
{
471-
//is this a folder?
472-
if (entry->d_type == DT_DIR){
473-
//does this folder have a valid executable inside?
474-
string p = string(path + dirsep + entry->d_name + dirsep + executable);
475-
if (file_exists(p)){
476-
//add it to the list
477-
a.Add(string(entry->d_name) + " - " + path);
478-
479-
//add it to the backing datastructure
480-
editor e = {entry->d_name, path};
481-
editors.push_back(e);
471+
if(dir != nullptr){
472+
struct dirent *entry = readdir(dir);
473+
//loop over the contents
474+
wxArrayString a;
475+
while (entry != nullptr)
476+
{
477+
//is this a folder?
478+
if (entry->d_type == DT_DIR){
479+
//does this folder have a valid executable inside?
480+
string p = string(path + dirsep + entry->d_name + dirsep + executable);
481+
if (file_exists(p)){
482+
//add it to the list
483+
a.Add(string(entry->d_name) + " - " + path);
484+
485+
//add it to the backing datastructure
486+
editor e = {entry->d_name, path};
487+
editors.push_back(e);
488+
}
482489
}
490+
entry = readdir(dir);
483491
}
484-
entry = readdir(dir);
492+
installsList->Append(a);
493+
//free resources when finished
494+
closedir(dir);
495+
free(entry);
485496
}
486-
installsList->Append(a);
487-
//free resources when finished
488-
closedir(dir);
489-
free(entry);
490497
}
491498
}

0 commit comments

Comments
 (0)