Fix a crash when opening an empty file.
Fixes: https://github.com/solvespace/solvespace/issues/918 The problem was that here:pull/922/head11a8a0abd5/src/file.cpp (L480)
we cleared all groups. Then we tried to read an empty file and therefore this `while` exited immediately:11a8a0abd5/src/file.cpp (L487)
and we came to here:11a8a0abd5/src/file.cpp (L548)
where there was no `fileLoadError` and thus we were left with no groups, and so this assert failed:11a8a0abd5/src/graphicswin.cpp (L394)
since is is not allowed to have no groups :-)
parent
11a8a0abd5
commit
1c5c4c048c
|
@ -468,6 +468,7 @@ void SolveSpaceUI::LoadUsingTable(const Platform::Path &filename, char *key, cha
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SolveSpaceUI::LoadFromFile(const Platform::Path &filename, bool canCancel) {
|
bool SolveSpaceUI::LoadFromFile(const Platform::Path &filename, bool canCancel) {
|
||||||
|
bool fileIsEmpty = true;
|
||||||
allConsistent = false;
|
allConsistent = false;
|
||||||
fileLoadError = false;
|
fileLoadError = false;
|
||||||
|
|
||||||
|
@ -485,6 +486,8 @@ bool SolveSpaceUI::LoadFromFile(const Platform::Path &filename, bool canCancel)
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
while(fgets(line, (int)sizeof(line), fh)) {
|
while(fgets(line, (int)sizeof(line), fh)) {
|
||||||
|
fileIsEmpty = false;
|
||||||
|
|
||||||
char *s = strchr(line, '\n');
|
char *s = strchr(line, '\n');
|
||||||
if(s) *s = '\0';
|
if(s) *s = '\0';
|
||||||
// We should never get files with \r characters in them, but mailers
|
// We should never get files with \r characters in them, but mailers
|
||||||
|
@ -545,6 +548,11 @@ bool SolveSpaceUI::LoadFromFile(const Platform::Path &filename, bool canCancel)
|
||||||
|
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
|
|
||||||
|
if(fileIsEmpty) {
|
||||||
|
Error(_("The file is empty. It may be corrupt."));
|
||||||
|
NewFile();
|
||||||
|
}
|
||||||
|
|
||||||
if(fileLoadError) {
|
if(fileLoadError) {
|
||||||
Error(_("Unrecognized data in file. This file may be corrupt, or "
|
Error(_("Unrecognized data in file. This file may be corrupt, or "
|
||||||
"from a newer version of the program."));
|
"from a newer version of the program."));
|
||||||
|
|
Loading…
Reference in New Issue