Don't abort if starnames.dat has not been loaded

Closes: #625
pull/645/head
Hleb Valoshka 2020-02-28 13:43:39 +03:00
parent 50f15ff5cd
commit 6eaa915873
2 changed files with 23 additions and 18 deletions

View File

@ -426,17 +426,21 @@ string StarDatabase::getStarNameList(const Star& star, const unsigned int maxNam
{
string starNames;
unsigned int catalogNumber = star.getCatalogNumber();
StarNameDatabase::NumberIndex::const_iterator iter = namesDB->getFirstNameIter(catalogNumber);
unsigned int count = 0;
while (iter != namesDB->getFinalNameIter() && iter->first == catalogNumber && count < maxNames)
{
if (count != 0)
starNames += " / ";
starNames += iter->second;
++iter;
++count;
if (namesDB != nullptr)
{
StarNameDatabase::NumberIndex::const_iterator iter = namesDB->getFirstNameIter(catalogNumber);
while (iter != namesDB->getFinalNameIter() && iter->first == catalogNumber && count < maxNames)
{
if (count != 0)
starNames += " / ";
starNames += iter->second;
++iter;
++count;
}
}
uint32_t hip = catalogNumber;

View File

@ -3902,18 +3902,17 @@ bool CelestiaCore::readStars(const CelestiaConfig& cfg,
{
StarDetails::SetStarTextures(cfg.starTextures);
StarNameDatabase* starNameDB = nullptr;
ifstream starNamesFile(cfg.starNamesFile.string(), ios::in);
if (!starNamesFile.good())
if (starNamesFile.good())
{
starNameDB = StarNameDatabase::readNames(starNamesFile);
if (starNameDB == nullptr)
cerr << _("Error reading star names file\n");
}
else
{
fmt::fprintf(cerr, _("Error opening %s\n"), cfg.starNamesFile);
return false;
}
StarNameDatabase* starNameDB = StarNameDatabase::readNames(starNamesFile);
if (starNameDB == nullptr)
{
cerr << _("Error reading star names file\n");
return false;
}
// First load the binary star database file. The majority of stars
@ -3942,6 +3941,8 @@ bool CelestiaCore::readStars(const CelestiaConfig& cfg,
}
}
if (starNameDB == nullptr)
starNameDB = new StarNameDatabase();
starDB->setNameDatabase(starNameDB);
loadCrossIndex(starDB, StarDatabase::HenryDraper, cfg.HDCrossIndexFile);