Skip to content

Commit 1397b83

Browse files
authored
76 bug save a constellation results in fatal assert on windows (#86)
* fix: assertion + perf: less value copies The assertion was a result because the SPainter was passed by value i.e. copied and not passed by reference * chore: merge mistake from main stellarium * fix: merge mistakes * chore: improved function signatures * fix: update error handling * chore: cleanup * fix: label not drawn
1 parent facc6f8 commit 1397b83

26 files changed

+340
-325
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ IF(WIN32)
307307
IF(NOT MSVC)
308308
# MinGW requires enabling of exceptions
309309
SET(STEL_MINGW_FLAGS "-fexceptions")
310-
# -Og and -s removes symbols an relocation information as otherwise the ordinal gets out of maximum 16-bit range.
310+
# -Og removes some symbols as otherwise the ordinal exceeds the maximum of the 16-bit range.
311311
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
312-
# MinGW clang compiler does not have a these flag, but MinGW gcc requires MinGW-specific threading, version number storage
312+
# MinGW clang compiler does not have these flags, but MinGW gcc requires MinGW-specific threading, version number storage
313313
IF(NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
314-
SET(STEL_MINGW_FLAGS "${STEL_MINGW_FLAGS} -fident -mthreads -s")
314+
SET(STEL_MINGW_FLAGS "${STEL_MINGW_FLAGS} -fident -mthreads")
315315
ENDIF()
316316
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STEL_GCC_C_FLAGS} ${STEL_MINGW_FLAGS}")
317317
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STEL_GCC_CXX_FLAGS} ${STEL_MINGW_FLAGS}")
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
#include "ScmAsterism.hpp"
22

3-
void scm::ScmAsterism::setCommonName(ScmCommonName name)
3+
void scm::ScmAsterism::setCommonName(const ScmCommonName &name)
44
{
5-
commonName = name;
5+
commonName = name;
66
}
77

8-
void scm::ScmAsterism::setId(QString id)
8+
void scm::ScmAsterism::setId(const QString &id)
99
{
10-
ScmAsterism::id = id;
10+
ScmAsterism::id = id;
1111
}
1212

1313
scm::ScmCommonName scm::ScmAsterism::getCommonName() const
1414
{
15-
return commonName;
15+
return commonName;
1616
}
1717

18-
1918
QString scm::ScmAsterism::getId() const
2019
{
21-
return id;
20+
return id;
2221
}

plugins/SkyCultureMaker/src/ScmAsterism.hpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,52 @@
99

1010
#ifndef SCM_ASTERISM_HPP
1111
#define SCM_ASTERISM_HPP
12-
13-
#include "ScmCommonName.hpp"
12+
1413
#include "QString"
15-
14+
#include "ScmCommonName.hpp"
15+
1616
namespace scm
1717
{
18-
18+
1919
class ScmAsterism
2020
{
2121
public:
22-
/**
22+
/**
2323
* @brief Sets the id of the asterism
2424
*
2525
* @param id id
2626
*/
27-
void setId(QString id);
27+
void setId(const QString &id);
2828

29-
/**
29+
/**
3030
* @brief Gets the id of the asterism
3131
*
3232
* @return id
3333
*/
34-
QString getId() const;
34+
QString getId() const;
3535

36-
/**
36+
/**
3737
* @brief Sets the common name of the asterism.
3838
*
3939
* @param name The common name of this asterim.
4040
*/
41-
void setCommonName(ScmCommonName name);
41+
void setCommonName(const ScmCommonName &name);
4242

43-
/**
43+
/**
4444
* @brief Returns the common name of the asterism.
4545
*
4646
* @return The common name of the this asterism.
4747
*/
48-
ScmCommonName getCommonName() const;
49-
48+
ScmCommonName getCommonName() const;
49+
5050
private:
51-
/// Id of the Asterism
52-
QString id;
51+
/// Id of the Asterism
52+
QString id;
5353

54-
/// Common name of the constellation
55-
ScmCommonName commonName;
54+
/// Common name of the constellation
55+
ScmCommonName commonName;
5656
};
5757

58-
} // namespace scm
58+
} // namespace scm
5959

60-
61-
#endif // SCM_ASTERISM_HPP
62-
60+
#endif // SCM_ASTERISM_HPP

plugins/SkyCultureMaker/src/ScmCommonName.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
#include "ScmCommonName.hpp"
22

3-
scm::ScmCommonName::ScmCommonName(QString id)
3+
scm::ScmCommonName::ScmCommonName(const QString &id)
44
{
55
ScmCommonName::id = id;
66
}
77

8-
void scm::ScmCommonName::setEnglishName(QString name)
8+
void scm::ScmCommonName::setEnglishName(const QString &name)
99
{
1010
englishName = name;
1111
}
1212

13-
void scm::ScmCommonName::setNativeName(QString name)
13+
void scm::ScmCommonName::setNativeName(const QString &name)
1414
{
1515
nativeName = name;
1616
}
1717

18-
void scm::ScmCommonName::setPronounce(QString pronounce)
18+
void scm::ScmCommonName::setPronounce(const QString &pronounce)
1919
{
2020
ScmCommonName::pronounce = pronounce;
2121
}
2222

23-
void scm::ScmCommonName::setIpa(QString ipa)
23+
void scm::ScmCommonName::setIpa(const QString &ipa)
2424
{
2525
ScmCommonName::ipa = ipa;
2626
}
2727

28-
void scm::ScmCommonName::setReferences(std::vector<int> refs)
28+
void scm::ScmCommonName::setReferences(const std::vector<int> &refs)
2929
{
3030
references = refs;
3131
}

plugins/SkyCultureMaker/src/ScmCommonName.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@
1010
#ifndef SCM_COMMONNAME_HPP
1111
#define SCM_COMMONNAME_HPP
1212

13-
#include <QString>
13+
#include <optional>
1414
#include <vector>
1515
#include <QJsonObject>
16-
#include <optional>
16+
#include <QString>
1717

1818
namespace scm
1919
{
2020

2121
class ScmCommonName
2222
{
2323
public:
24-
ScmCommonName(QString id);
24+
ScmCommonName(const QString &id);
2525

2626
/// Sets the english name
27-
void setEnglishName(QString name);
27+
void setEnglishName(const QString &name);
2828

2929
/// Sets the native name
30-
void setNativeName(QString name);
30+
void setNativeName(const QString &name);
3131

3232
/// Sets the native name in European glyphs or Pinyin for Chinese.
33-
void setPronounce(QString pronounce);
33+
void setPronounce(const QString &pronounce);
3434

3535
/// Sets the native name in IPA (International Phonetic Alphabet)
36-
void setIpa(QString name);
36+
void setIpa(const QString &name);
3737

3838
/// Sets the references to the sources of the name spellings
39-
void setReferences(std::vector<int> refs);
39+
void setReferences(const std::vector<int> &refs);
4040

4141
/// Returns the english name
4242
QString getEnglishName() const;
@@ -80,6 +80,6 @@ class ScmCommonName
8080
std::optional<std::vector<int>> references;
8181
};
8282

83-
} // namespace scm
83+
} // namespace scm
8484

85-
#endif // SCM_COMMONNAME_HPP
85+
#endif // SCM_COMMONNAME_HPP
Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
#include "ScmConstellation.hpp"
22

3-
scm::ScmConstellation::ScmConstellation(std::vector<scm::CoordinateLine> coordinates, std::vector<scm::StarLine> stars)
3+
scm::ScmConstellation::ScmConstellation(const std::vector<scm::CoordinateLine> &coordinates,
4+
const std::vector<scm::StarLine> &stars)
45
: constellationCoordinates(coordinates)
56
, constellationStars(stars)
67
{
7-
QSettings* conf = StelApp::getInstance().getSettings();
8+
QSettings *conf = StelApp::getInstance().getSettings();
89
constellationLabelFont.setPixelSize(conf->value("viewing/constellation_font_size", 15).toInt());
9-
10+
1011
QString defaultColor = conf->value("color/default_color", "0.5,0.5,0.7").toString();
11-
colorDrawDefault = Vec3f(conf->value("color/const_lines_color", defaultColor).toString());
12-
colorLabelDefault = Vec3f(conf->value("color/const_names_color", defaultColor).toString());
12+
colorDrawDefault = Vec3f(conf->value("color/const_lines_color", defaultColor).toString());
13+
colorLabelDefault = Vec3f(conf->value("color/const_names_color", defaultColor).toString());
14+
15+
updateTextPosition();
1316
}
1417

15-
void scm::ScmConstellation::setId(QString id)
18+
void scm::ScmConstellation::setId(const QString &id)
1619
{
1720
ScmConstellation::id = id;
1821
}
@@ -22,7 +25,7 @@ QString scm::ScmConstellation::getId() const
2225
return id;
2326
}
2427

25-
void scm::ScmConstellation::setEnglishName(QString name)
28+
void scm::ScmConstellation::setEnglishName(const QString &name)
2629
{
2730
englishName = name;
2831
}
@@ -32,56 +35,54 @@ QString scm::ScmConstellation::getEnglishName() const
3235
return englishName;
3336
}
3437

35-
void scm::ScmConstellation::setNativeName(std::optional<QString> name)
38+
void scm::ScmConstellation::setNativeName(const std::optional<QString> &name)
3639
{
3740
nativeName = name;
3841
}
3942

40-
void scm::ScmConstellation::setPronounce(std::optional<QString> pronounce)
43+
void scm::ScmConstellation::setPronounce(const std::optional<QString> &pronounce)
4144
{
4245
ScmConstellation::pronounce = pronounce;
4346
}
4447

45-
void scm::ScmConstellation::setIPA(std::optional<QString> ipa)
48+
void scm::ScmConstellation::setIPA(const std::optional<QString> &ipa)
4649
{
4750
ScmConstellation::ipa = ipa;
4851
}
4952

50-
void scm::ScmConstellation::setConstellation(std::vector<CoordinateLine> coordinates, std::vector<StarLine> stars)
53+
void scm::ScmConstellation::setConstellation(const std::vector<CoordinateLine> &coordinates,
54+
const std::vector<StarLine> &stars)
5155
{
5256
constellationCoordinates = coordinates;
53-
constellationStars = stars;
57+
constellationStars = stars;
58+
59+
updateTextPosition();
5460
}
5561

56-
void scm::ScmConstellation::drawConstellation(StelCore *core, Vec3f color)
62+
void scm::ScmConstellation::drawConstellation(StelCore *core, const Vec3f &color) const
5763
{
5864
StelPainter painter(core->getProjection(drawFrame));
5965
painter.setBlending(true);
6066
painter.setLineSmooth(true);
6167
painter.setFont(constellationLabelFont);
62-
68+
6369
bool alpha = 1.0f;
6470
painter.setColor(color, alpha);
6571

66-
XYZname.set(0.,0.,0.);
6772
for (CoordinateLine p : constellationCoordinates)
6873
{
6974
painter.drawGreatCircleArc(p.start, p.end);
70-
XYZname += p.end;
71-
XYZname += p.start;
7275
}
7376

74-
XYZname.normalize();
75-
76-
drawNames(core, painter, colorLabelDefault);
77+
drawNames(core, painter);
7778
}
7879

79-
void scm::ScmConstellation::drawConstellation(StelCore *core)
80+
void scm::ScmConstellation::drawConstellation(StelCore *core) const
8081
{
8182
drawConstellation(core, colorDrawDefault);
8283
}
8384

84-
void scm::ScmConstellation::drawNames(StelCore *core, StelPainter sPainter, Vec3f labelColor)
85+
void scm::ScmConstellation::drawNames(StelCore *core, StelPainter &sPainter, const Vec3f &labelColor) const
8586
{
8687
sPainter.setBlending(true);
8788

@@ -91,26 +92,27 @@ void scm::ScmConstellation::drawNames(StelCore *core, StelPainter sPainter, Vec3
9192
velocityObserver = core->getAberrationVec(core->getJDE());
9293
}
9394

94-
XYZname+=velocityObserver;
95-
XYZname.normalize();
95+
Vec3d namePose = XYZname;
96+
namePose += velocityObserver;
97+
namePose.normalize();
9698

97-
if(!sPainter.getProjector()->projectCheck(XYZname, this->XYname))
99+
Vec3d XYname;
100+
if (!sPainter.getProjector()->projectCheck(XYZname, XYname))
98101
{
99102
return;
100103
}
101104

102-
sPainter.getProjector()->project(XYZname, XYname);
103105
sPainter.setColor(labelColor, 1.0f);
104-
sPainter.drawText(static_cast<float>(XYname[0]), static_cast<float>(XYname[1]), englishName, 0., -sPainter.getFontMetrics().boundingRect(englishName).width()/2, 0, false);
106+
sPainter.drawText(static_cast<float>(XYname[0]), static_cast<float>(XYname[1]), englishName, 0.,
107+
-sPainter.getFontMetrics().boundingRect(englishName).width() / 2, 0, false);
105108
}
106109

107-
void scm::ScmConstellation::drawNames(StelCore *core, StelPainter sPainter)
110+
void scm::ScmConstellation::drawNames(StelCore *core, StelPainter &sPainter) const
108111
{
109112
drawNames(core, sPainter, colorLabelDefault);
110113
}
111114

112-
113-
QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
115+
QJsonObject scm::ScmConstellation::toJson(const QString &skyCultureName) const
114116
{
115117
QJsonObject json;
116118

@@ -120,7 +122,7 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
120122
if (constellationStars.size() != 0)
121123
{
122124
// Stars are NOT empty
123-
for (const auto &star: constellationStars)
125+
for (const auto &star : constellationStars)
124126
{
125127
linesArray.append(star.toJson());
126128
}
@@ -134,7 +136,7 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
134136
}
135137
}
136138

137-
json["id"] = "CON " + skyCultureName + " " + id;
139+
json["id"] = "CON " + skyCultureName + " " + id;
138140
json["lines"] = linesArray;
139141

140142
// Assemble common name object
@@ -155,7 +157,7 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
155157
if (references.has_value() && !references->isEmpty())
156158
{
157159
QJsonArray refsArray;
158-
for (const auto& ref : references.value())
160+
for (const auto &ref : references.value())
159161
{
160162
refsArray.append(ref);
161163
}
@@ -164,4 +166,15 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
164166
json["common_name"] = commonNameObj;
165167

166168
return json;
167-
}
169+
}
170+
171+
void scm::ScmConstellation::updateTextPosition()
172+
{
173+
XYZname.set(0., 0., 0.);
174+
for (CoordinateLine p : constellationCoordinates)
175+
{
176+
XYZname += p.end;
177+
XYZname += p.start;
178+
}
179+
XYZname.normalize();
180+
}

0 commit comments

Comments
 (0)