Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix discovery of document version number #845

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/initialization/FGInitialCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,21 +1027,23 @@ bool FGInitialCondition::Load(const SGPath& rstfile, bool useStoredPath)
throw BaseException(s.str());
}

double version = HUGE_VAL;
bool result = false;

if (document->HasAttribute("version"))
version = document->GetAttributeValueAsNumber("version");

if (version == HUGE_VAL) {
result = Load_v1(document); // Default to the old version
} else if (version >= 3.0) {
const string s("Only initialization file formats 1 and 2 are currently supported");
cerr << document->ReadFrom() << endl << s << endl;
throw BaseException(s);
} else if (version >= 2.0) {
result = Load_v2(document);
} else if (version >= 1.0) {
// If doc has an version, check it. Otherwise fall back to legacy.
if (document->HasAttribute("version")) {
double version = document->GetAttributeValueAsNumber("version");

if (version >= 3.0) {
const string s("Only initialization file formats 1 and 2 are currently supported");
cerr << document->ReadFrom() << endl << s << endl;
throw BaseException(s);
} else if (version >= 2.0) {
result = Load_v2(document);
} else if (version >= 1.0) {
result = Load_v1(document);
}

} else {
result = Load_v1(document);
}

Expand Down