Repository: Stellarium/stellarium
Pull request #4203: Don't load any high level star catalog if a lower level star catalog is missing
Author: login: henrysky
Labels: name: subsystem: catalogs
description: The issue is related to supported catalogs of planetarium...
Created: 2025-03-13T03:26:50Z | Merged: 2025-03-13T17:01:38Z

Don't load any high level star catalog if a lower level star catalog is missing. Warning is provided, telling user a star catalog is found but not loaded because a lower level star catalog is missing.

Fixes #4181

### Screenshots (if appropriate):

### Type of change
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] This change requires a documentation update
- [ ] Housekeeping

### How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

**Test Configuration**:
* Operating system: MacOS 15
* Graphics Card: Apple M3

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the [code style](http://stellarium.org/doc/head/codingStyle.html) of this project.
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation (header file)
- [ ] I have updated the respective chapter in the Stellarium User Guide
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules


Linked issue #4181: Stellarium Weekly Snapshot crashes when starting on a low configuration computer with Windows 10
<!--
READ THIS AND FILL IN THIS TEMPLATE!

Before reporting an issue around graphics artifacts like missing menu buttons, strange colors, Moon not rendered, or similar, 
*please make absolutely sure* you are running the latest graphics drivers for your graphics card. 
95% of graphics problems are solved this way.

Before reporting an issue, please *absolutely make sure* to check the recent open and also closed issues 
(https://github.com/Stellarium/stellarium/issues?q=is%3Aissue+is%3Aclosed) 
whether it has been reported and solved/closed already! Don't report a new issue in this case, you may join the discussion.

Sometimes installing our almost weekly Beta version (i.e., the latest development version) helps: https://github.com/Stellarium/stellarium-data/releases/tag/beta

Also look into the wiki https://github.com/Stellarium/stellarium/wiki/Common-Problems-for-the-current-version 
and FAQ https://github.com/Stellarium/stellarium/wiki/FAQ 
and check if you are attempting to report a known issue. Don't report in this case.

Also look into the User Guide before reporting unexpected but correct behaviour. Don't report in this case.

If you miss translations, please help us with your language and join our translators at Transifex: https://app.transifex.com/stellarium/stellarium/dashboard/

If you want to report a feature wish, delete these template lines above and below, and fill in. 

If you want to report a bug, please make sure to update and verify the bug still exists in the current version. 
In this case please also check current beta builds from http://stellarium.org

If the bug still persists, give your issue a clear, short title, delete text above down to and including this line and fill in:
-->

### Expected Behaviour

### Actual Behaviour
It seems to have crashed while loading the exoplanet plug-in.

[log.txt](https://github.com/user-attachments/files/19120707/log.txt)

### Steps to reproduce

### System
* Stellarium version: <Name of downloaded installable file?>
* Operating system: <Name, version number>
* Graphics Card: <Manufacturer (likely Intel, NVidia, AMD?), Model (HD, Geforce, Radeon..., with model number), driver version?>
* Screen type (if applicable): Resolution, HighDPI, scaling

### Logfile 
If possible, attach the logfile `log.txt` from your user data directory. Look into the Guide for its location.

Linked issue comments: user: login: alex-w
created_at: 2025-03-07T05:39:39Z
body: Please see in the log:
```
[     6.642][INFO] Loading star data ...
[     6.644][INFO] Loading star catalog: .\stars\hip_gaia3\stars_0_0v0_16.cat - 0_0v0_16; 5046 entries
[     6.645][INFO] Loading star catalog: .\stars\hip_gaia3\stars_1_0v0_15.cat - 1_0v0_15; 21611 entries
[     6.646][INFO] Loading star catalog: .\stars\hip_gaia3\stars_2_0v0_16.cat - 2_0v0_16; 141761 entries
[     6.647][INFO] Loading star catalog: .\stars\hip_gaia3\stars_3_0v0_10.cat - 3_0v0_10; 418129 entries
[     6.649][WARN] Found file .\stars\hip_gaia3\stars_7_1v0_3.cat , checking md5sum...
[    18.599][WARN] MD5 sum correct!
[    18.620][INFO] Loading star catalog: .\stars\hip_gaia3\stars_7_1v0_3.cat - 7_1v0_3; 57534724 entries
[    18.622][WARN] Found file .\stars\hip_gaia3\stars_8_2v0_3.cat , checking md5sum...
[    30.835][WARN] MD5 sum correct!
[    30.948][INFO] Loading star catalog: .\stars\hip_gaia3\stars_8_2v0_3.cat - 8_2v0_2; 122908184 entries
[    31.218][INFO] Finished loading star catalogue data, max_geodesic_level: 5
```

You have missing parts of star catalogues (parts 4, 5, and 6)
author_association: MEMBER
user: login: alex-w
created_at: 2025-03-07T05:47:10Z
body: @gzotti @10110111 @henrysky 

In one hand this is expected behaviour when some parts (in the middle) of star catalog are missing and max. geodesic level is wrong (problem in line 586 in StarMgr.cpp file - ASSERT). In other hand we should handling similar situations.
author_association: MEMBER
user: login: 10110111
created_at: 2025-03-07T05:49:22Z
body: If some intermediate levels are missing, the total should be limited the highest level of the contiguous set (with appropriate warnings in the log).
author_association: CONTRIBUTOR
user: login: sunshuwei
created_at: 2025-03-07T06:10:14Z
body: I understand now, the original star directory was not automatically updated to the new version during installation, which resulted in a conflict.
author_association: CONTRIBUTOR
user: login: alex-w
created_at: 2025-03-07T06:12:35Z
body: > I understand now, the original star directory was not automatically updated to the new version during installation, which resulted in a conflict.

Not a conflict, just Exoplanets plugin tried search stars in not existed catalog
author_association: MEMBER
user: login: github-actions[bot]
created_at: 2025-03-17T17:51:42Z
body: 

Hello @sunshuwei!

Please check the fresh version (development snapshot) of Stellarium:
https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot



author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-23T18:06:59Z
body: 

Hello @sunshuwei!

Please check the latest stable version of Stellarium:
https://github.com/Stellarium/stellarium/releases/latest



author_association: NONE

Diff:
diff --git a/doc/fileStructure.doxygen b/doc/fileStructure.doxygen
index 281238f745730..d784b77002854 100644
--- a/doc/fileStructure.doxygen
+++ b/doc/fileStructure.doxygen
@@ -129,7 +129,7 @@ The catalogue downloader tool runs within Stellarium.  When it downloads extra s
 <User Data Directory>/stars/hip_gaia3/stars_4_1v0_6.cat
 <User Data Directory>/stars/hip_gaia3/stars_5_1v0_6.cat
 <User Data Directory>/stars/hip_gaia3/stars_6_1v0_4.cat
-<User Data Directory>/stars/hip_gaia3/stars_7_1v0_3.cat
+<User Data Directory>/stars/hip_gaia3/stars_7_1v0_4.cat
 <User Data Directory>/stars/hip_gaia3/stars_8_2v0_3.cat
 @endverbatim
 
diff --git a/guide/app_star_catalogue.tex b/guide/app_star_catalogue.tex
index 2bcde9d3588d3..cff1e90257cec 100644
--- a/guide/app_star_catalogue.tex
+++ b/guide/app_star_catalogue.tex
@@ -62,7 +62,7 @@ \subsection{General Description}%\label{general-description}
 \item[\file{stars\_4\_1v0\_6.cat}]
 \item[\file{stars\_5\_1v0\_6.cat}]
 \item[\file{stars\_6\_1v0\_4.cat}]
-\item[\file{stars\_7\_1v0\_3.cat}]
+\item[\file{stars\_7\_1v0\_4.cat}]
 \item[\file{stars\_8\_2v0\_3.cat}]
 \end{description}
 
@@ -111,8 +111,8 @@ \subsection{General Description}%\label{general-description}
 \file{stars\_4\_1v0\_6.cat}  & 1 & 32 bytes & 4 &    1,741,849 & Gaia\\
 \file{stars\_5\_1v0\_6.cat}  & 1 & 32 bytes & 5 &    8,051,933 & Gaia\\
 \file{stars\_6\_1v0\_4.cat}  & 1 & 32 bytes & 6 &   29,879,734 & Gaia\\
-\file{stars\_7\_1v0\_3.cat}  & 1 & 32 bytes & 7 &   57,534,724 & Gaia\\
-\file{stars\_8\_2v0\_3.cat}  & 2 & 16 bytes & 8 & 1,229,081,84 & Gaia\\
+\file{stars\_7\_1v0\_4.cat}  & 1 & 32 bytes & 7 &   57,534,724 & Gaia\\
+\file{stars\_8\_2v0\_3.cat}  & 2 & 16 bytes & 8 &  122,908,184 & Gaia\\
 \bottomrule
 \end{tabular}
 
diff --git a/src/core/modules/StarMgr.cpp b/src/core/modules/StarMgr.cpp
index b9ff864f23607..91926423f937e 100644
--- a/src/core/modules/StarMgr.cpp
+++ b/src/core/modules/StarMgr.cpp
@@ -497,7 +497,7 @@ void StarMgr::drawPointer(StelPainter& sPainter, const StelCore* core)
 	}
 }
 
-bool StarMgr::checkAndLoadCatalog(const QVariantMap& catDesc)
+bool StarMgr::checkAndLoadCatalog(const QVariantMap& catDesc, const bool load)
 {
 	const bool checked = catDesc.value("checked").toBool();
 	QString catalogFileName = catDesc.value("fileName").toString();
@@ -574,21 +574,28 @@ bool StarMgr::checkAndLoadCatalog(const QVariantMap& catDesc)
 		}
 	}
 
-	ZoneArray* z = ZoneArray::create(catalogFilePath, true);
-	if (z)
-	{
-		if (z->level<gridLevels.size())
+	if (load) {
+		ZoneArray* z = ZoneArray::create(catalogFilePath, true);
+		if (z)
 		{
-			qWarning().noquote() << QDir::toNativeSeparators(catalogFileName) << ", " << z->level << ": duplicate level";
-			delete z;
-			return true;
+			if (z->level<gridLevels.size())
+			{
+				qWarning().noquote() << QDir::toNativeSeparators(catalogFileName) << ", " << z->level << ": duplicate level";
+				delete z;
+				return true;
+			}
+			Q_ASSERT(z->level==maxGeodesicGridLevel+1);
+			Q_ASSERT(z->level==gridLevels.size());
+			++maxGeodesicGridLevel;
+			gridLevels.append(z);
 		}
-		Q_ASSERT(z->level==maxGeodesicGridLevel+1);
-		Q_ASSERT(z->level==gridLevels.size());
-		++maxGeodesicGridLevel;
-		gridLevels.append(z);
+		return true;
+	}
+	else
+	{
+		qWarning().noquote() << "Star catalog: " << QDir::toNativeSeparators(catalogFileName) << "is found but not loaded because at least one of the lower levels is missing!";
+		return false;
 	}
-	return true;
 }
 
 void StarMgr::setCheckFlag(const QString& catId, bool b)
@@ -624,10 +631,11 @@ void StarMgr::loadData(QVariantMap starsConfig)
 	qInfo() << "Loading star data ...";
 
 	catalogsDescription = starsConfig.value("catalogs").toList();
+	bool isSuccessing = true;
 	foreach (const QVariant& catV, catalogsDescription)
 	{
 		QVariantMap m = catV.toMap();
-		checkAndLoadCatalog(m);
+		isSuccessing = checkAndLoadCatalog(m, isSuccessing);
 	}
 
 	for (int i=0; i<=NR_OF_HIP; i++)
diff --git a/src/core/modules/StarMgr.hpp b/src/core/modules/StarMgr.hpp
index 14c0a46cf408d..49131b6681b9b 100644
--- a/src/core/modules/StarMgr.hpp
+++ b/src/core/modules/StarMgr.hpp
@@ -420,8 +420,10 @@ public slots:
 
 	//! Try to load the given catalog, even if it is marched as unchecked.
 	//! Mark it as checked if checksum is correct.
+	//! @param m the catalog data.
+	//! @param load true if the catalog should be loaded, otherwise just check but don't load.
 	//! @return false in case of failure.
-	bool checkAndLoadCatalog(const QVariantMap& m);
+	bool checkAndLoadCatalog(const QVariantMap& m, bool load);
 
 	//! Get the list of all Hipparcos stars.
 	const QList<StelObjectP>& getHipparcosStars() const { return hipparcosStars; }	
diff --git a/src/gui/ConfigurationDialog.cpp b/src/gui/ConfigurationDialog.cpp
index 303f89d95e42d..abbf4ead01dbb 100644
--- a/src/gui/ConfigurationDialog.cpp
+++ b/src/gui/ConfigurationDialog.cpp
@@ -1724,7 +1724,7 @@ void ConfigurationDialog::downloadFinished()
 	progressBar=Q_NULLPTR;
 
 	ui->downloadLabel->setText(q_("Verifying file integrity..."));
-	if (GETSTELMODULE(StarMgr)->checkAndLoadCatalog(nextStarCatalogToDownload)==false)
+	if (GETSTELMODULE(StarMgr)->checkAndLoadCatalog(nextStarCatalogToDownload, true)==false)
 	{
 		ui->getStarsButton->setVisible(false);
 		ui->downloadLabel->setText(q_("Error downloading %1:\nFile is corrupted.").arg(nextStarCatalogToDownload.value("id").toString()));


Reviews:
user: login: 10110111
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T03:37:51Z
user: login: henrysky
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T04:22:48Z
user: login: alex-w
body: Thanks!
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-13T17:00:01Z

Review comments:
diff_hunk: @@ -624,10 +631,11 @@ void StarMgr::loadData(QVariantMap starsConfig)
 	qInfo() << "Loading star data ...";
 
 	catalogsDescription = starsConfig.value("catalogs").toList();
+	bool hasFailed = false;
 	foreach (const QVariant& catV, catalogsDescription)
 	{
 		QVariantMap m = catV.toMap();
-		checkAndLoadCatalog(m);
+		hasFailed = not checkAndLoadCatalog(m, not hasFailed);
path: src/core/modules/StarMgr.cpp
user: login: 10110111
body: May be better to avoid these lots of negations and just use `success` instead of `hasFailed`.
created_at: 2025-03-13T03:37:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -624,10 +631,11 @@ void StarMgr::loadData(QVariantMap starsConfig)
 	qInfo() << "Loading star data ...";
 
 	catalogsDescription = starsConfig.value("catalogs").toList();
+	bool hasFailed = false;
 	foreach (const QVariant& catV, catalogsDescription)
 	{
 		QVariantMap m = catV.toMap();
-		checkAndLoadCatalog(m);
+		hasFailed = not checkAndLoadCatalog(m, not hasFailed);
path: src/core/modules/StarMgr.cpp
user: login: henrysky
body: fixed, thanks!
created_at: 2025-03-13T04:22:48Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-03-13T03:27:28Z
body: Great PR! Please pay attention to the following items before merging:

__Files matching `src/**/*.cpp`:__
- [ ] Are possibly unused includes removed?


This is an automatically generated QA checklist based on modified files.
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-17T17:54:34Z
body: 

Hello @henrysky!

Please check the fresh version (development snapshot) of Stellarium:
https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot



author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-23T18:04:03Z
body: 

Hello @henrysky!

Please check the latest stable version of Stellarium:
https://github.com/Stellarium/stellarium/releases/latest



author_association: NONE