Skip to content

Commit afaa218

Browse files
authored
Fix gdal driver registration (#5805)
* Fix gdal driver registration * Added changelog entry * Fix tests that use GDAL Drivers/need errors silenced
1 parent eab1542 commit afaa218

File tree

9 files changed

+41
-11
lines changed

9 files changed

+41
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ ctest FunctionalTestJigsawApollo to validate this output. [#5710](https://github
6969
- Fixed jigsaw save/apply bug by adding back missing metadata to Instrument Position/Pointing tables [#5701](https://github.com/DOI-USGS/ISIS3/issues/5701)
7070
- Fixed `StripPolygonSeeder` and `GridPolygonSeeder` memory leaks [#5193](https://github.com/DOI-USGS/ISIS3/issues/5193)
7171
- Fixed `pointreg` helper function to display deffile to application log [#5806](https://github.com/DOI-USGS/ISIS3/pull/5806)
72+
- Fixed ISIS Q Applications crashing when opening more than one cube at once. [#5805](https://github.com/DOI-USGS/ISIS3/pull/5805)
7273

7374
## [9.0.0] - 09-25-2024
7475

isis/src/base/objs/Application/Application.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern int errno;
2525
#include <QString>
2626
#include <QTime>
2727

28+
#include "gdal_priv.h"
29+
2830
#include "Application.h"
2931
#include "FileName.h"
3032
#include "IException.h"
@@ -91,6 +93,16 @@ namespace Isis {
9193
p_startPageFaults = PageFaults();
9294
p_startProcessSwaps = ProcessSwaps();
9395

96+
// Setup gdal drivers and error handler
97+
try {
98+
GDALAllRegister();
99+
CPLSetErrorHandler(CPLQuietErrorHandler);
100+
}
101+
catch(exception &e) {
102+
QString msg = "Failed to load GDAL Drivers, with error [" + QString(e.what()) + "]";
103+
throw IException(IException::Unknown, msg, _FILEINFO_);
104+
}
105+
94106
// Create user interface and log
95107
try {
96108
FileName f(QString(argv[0]) + ".xml");

isis/src/base/objs/Cube/Cube.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ using namespace std;
4848
namespace Isis {
4949
//! Constructs a Cube object.
5050
Cube::Cube() {
51-
GDALAllRegister();
52-
CPLSetErrorHandler(CPLQuietErrorHandler);
5351
construct();
5452
}
5553

@@ -62,8 +60,6 @@ namespace Isis {
6260
* "r" or read-write "rw".
6361
*/
6462
Cube::Cube(const FileName &fileName, QString access) {
65-
GDALAllRegister();
66-
CPLSetErrorHandler(CPLQuietErrorHandler);
6763
construct();
6864
open(fileName.toString(), access);
6965
}
@@ -78,8 +74,6 @@ namespace Isis {
7874
* "r" or read-write "rw".
7975
*/
8076
void Cube::fromLabel(const FileName &fileName, Pvl &label, QString access) {
81-
GDALAllRegister();
82-
CPLSetErrorHandler(CPLQuietErrorHandler);
8377
initCoreFromLabel(label);
8478
create(fileName.expanded());
8579

@@ -103,8 +97,6 @@ namespace Isis {
10397
* "r" or read-write "rw".
10498
*/
10599
void Cube::fromIsd(const FileName &fileName, Pvl &label, nlohmann::json &isd, QString access) {
106-
GDALAllRegister();
107-
CPLSetErrorHandler(CPLQuietErrorHandler);
108100
fromLabel(fileName, label, access);
109101

110102
PvlGroup &instGrp = label.findGroup("Instrument", Pvl::Traverse);
@@ -670,8 +662,6 @@ namespace Isis {
670662
}
671663

672664
void Cube::createGdal(QString &dataFileName, QString &driverName, char **papszOptions) {
673-
GDALAllRegister();
674-
CPLSetErrorHandler(CPLQuietErrorHandler);
675665
GDALDriver* driver = GetGDALDriverManager()->GetDriverByName(driverName.toStdString().c_str());
676666
if (driver) {
677667
double noDataValue;

isis/src/base/objs/CubeManager/unitTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ using namespace Isis;
1818

1919
int main(int argc, char *argv[]) {
2020
Isis::Preference::Preferences(true);
21+
GDALAllRegister();
22+
CPLSetErrorHandler(CPLQuietErrorHandler);
2123

2224
cout << "CubeManager Unit Test" << endl;
2325
QVector<Cube *> cubes;

isis/src/base/objs/ImageIoHandler/GdalIoHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ using namespace std;
1919
namespace Isis {
2020
GdalIoHandler::GdalIoHandler(QString &dataFilePath, const QList<int> *virtualBandList, GDALDataType pixelType, GDALAccess eAccess) :
2121
ImageIoHandler(virtualBandList) {
22-
GDALAllRegister();
2322
m_geodataSetPath = dataFilePath.toUtf8().constData();
2423
m_geodataSet = GDALDataset::FromHandle(GDALOpen(m_geodataSetPath.c_str(), eAccess));
2524
m_datasetOwner = true;

isis/src/base/objs/ShapeModelFactory/unitTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ using namespace Isis;
4747
}
4848

4949
int main() {
50+
GDALAllRegister();
51+
CPLSetErrorHandler(CPLQuietErrorHandler);
52+
5053
try {
5154
Isis::Preference::Preferences(true);
5255

isis/src/base/objs/SpectralDefinitionFactory/unitTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ using namespace Isis;
1818

1919
int main(int argc, char *argv[]) {
2020
Preference::Preferences(true);
21+
GDALAllRegister();
22+
CPLSetErrorHandler(CPLQuietErrorHandler);
2123

2224
cerr.precision(14);
2325

isis/src/qisis/objs/QIsisApplication/QIsisApplication.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <QMessageBox>
99
#include <QUrl>
1010

11+
#include <gdal_priv.h>
12+
1113
#include "FileName.h"
1214
#include "Preference.h"
1315
#include "IException.h"
@@ -30,6 +32,16 @@ namespace Isis {
3032
// try to use US locale for numbers so we don't end up printing "," instead
3133
// of "." where it might count.
3234

35+
// Setup gdal drivers and error handler
36+
try {
37+
GDALAllRegister();
38+
CPLSetErrorHandler(CPLQuietErrorHandler);
39+
}
40+
catch(std::exception &e) {
41+
QString msg = "Failed to load GDAL Drivers, with error [" + QString(e.what()) + "]";
42+
throw IException(IException::Unknown, msg, _FILEINFO_);
43+
}
44+
3345
for (int i = 1; i < argc; i++) {
3446
QString arg(argv[i]);
3547
if (arg.startsWith("-pref")) {

isis/tests/GTiffTests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void check_tiff(Cube &cube,
5858

5959

6060
TEST_F(TempTestingFiles, TestGTiffCreateWriteCopy) {
61+
GDALAllRegister();
62+
CPLSetErrorHandler(CPLQuietErrorHandler);
63+
6164
Cube out;
6265
QString file = "";
6366
check_tiff(out, file, 0, 0, 0, 0, 1, 7, 0, 1, 0, 0, 0, 65536);
@@ -121,6 +124,9 @@ INSTANTIATE_TEST_SUITE_P (GdalDnPixelTypes,
121124
Isis::Double));
122125

123126
TEST_P(GdalDnTypeGenerator, TestGTiffCreateWrite) {
127+
GDALAllRegister();
128+
CPLSetErrorHandler(CPLQuietErrorHandler);
129+
124130
Cube out;
125131
QString file = "";
126132
check_tiff(out, file, 0, 0, 0, 0, 1, 7, 0, 1, 0, 0, 0, 65536);
@@ -176,6 +182,9 @@ TEST_P(GdalDnTypeGenerator, TestGTiffCreateWrite) {
176182
}
177183

178184
TEST_F(TempTestingFiles, TestGTiffTableWriteRead) {
185+
GDALAllRegister();
186+
CPLSetErrorHandler(CPLQuietErrorHandler);
187+
179188
TableField f1("Column1", TableField::Integer);
180189
TableField f2("Column2", TableField::Double);
181190
TableField f3("Column3", TableField::Text, 10);

0 commit comments

Comments
 (0)