Skip to content

Commit 4fb1d10

Browse files
committed
Fix intermittent crash in ecflow_ui ECFLOW-2093
2 parents e17b47b + 107f012 commit 4fb1d10

7 files changed

Lines changed: 104 additions & 29 deletions

File tree

Viewer/ecflowUI/src/ServerHandler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ void ServerHandler::logoutAndDelete() {
140140
}
141141

142142
delete vRoot_;
143+
vRoot_ = nullptr;
143144
delete connectState_;
145+
connectState_ = nullptr;
144146
delete suiteFilter_;
147+
suiteFilter_ = nullptr;
145148
delete conf_;
149+
conf_ = nullptr;
146150

147151
if (queueLoggedOut) {
148152
deleteLater();

Viewer/ecflowUI/src/TreeNodeModel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ QVariant TreeNodeModel::attributesData(const QModelIndex& index, int role, VTree
374374
// - and, assigned to a Node that is synchronised to (i.e. a mirror of) a Node in an external ecFlow server;
375375
// we customize the foreground colour.
376376
if (VAttribute* a = vnode->attribute(index.row(), atts_);
377-
a && a->type()->name() == "var" && vnode->node()->isMirror()) {
377+
a && a->type()->name() == "var" && vnode->node() && vnode->node()->isMirror()) {
378378
return QColor(119, 153, 170);
379379
}
380380
else {

Viewer/ecflowUI/src/VNode.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,13 @@ QColor VNode::typeFontColour() const {
721721
}
722722

723723
bool VNode::userLogServer(std::string& host, std::string& port) {
724-
if (ServerHandler* sh = server()) {
725-
host = sh->conf()->stringValue(VServerSettings::UserLogServerHost).toStdString();
726-
if (!host.empty()) {
727-
port = sh->conf()->stringValue(VServerSettings::UserLogServerPort).toStdString();
728-
return !port.empty();
724+
if (auto* sh = server(); sh) {
725+
if (auto* conf = sh->conf(); conf) {
726+
host = conf->stringValue(VServerSettings::UserLogServerHost).toStdString();
727+
if (!host.empty()) {
728+
port = conf->stringValue(VServerSettings::UserLogServerPort).toStdString();
729+
return !port.empty();
730+
}
729731
}
730732
}
731733
return false;
@@ -1199,7 +1201,10 @@ void VServer::clear() {
11991201

12001202
attrForSearch_.clear();
12011203

1202-
bool hasNotifications = server_->conf()->notificationsEnabled();
1204+
bool hasNotifications = false;
1205+
if (auto* conf = server_->conf(); conf) {
1206+
hasNotifications = conf->notificationsEnabled();
1207+
}
12031208

12041209
// Delete the children nodes. It will recursively delete all the nodes. It also saves the prevNodeState!!
12051210
for (auto it = children_.begin(); it != children_.end(); ++it) {
@@ -1383,7 +1388,10 @@ void VServer::endScan() {
13831388
return;
13841389
}
13851390

1386-
bool hasNotifications = server_->conf()->notificationsEnabled();
1391+
bool hasNotifications = false;
1392+
if (auto* conf = server_->conf(); conf) {
1393+
hasNotifications = conf->notificationsEnabled();
1394+
}
13871395

13881396
// Scan the suits.This will recursively scan all nodes in the tree.
13891397
for (const auto& suite : defs->suites()) {
@@ -1471,15 +1479,15 @@ void VServer::beginUpdate(VNode* node, const std::vector<ecf::Aspect::Type>& asp
14711479
// update.
14721480

14731481
// Update the generated variables. There is no notification about their change so we have to do it!!!
1474-
if (node->node()) {
1482+
if (auto n = node->node(); n) {
14751483
Suite* s = nullptr;
1476-
s = node->node()->isSuite();
1484+
s = n->isSuite();
14771485
if (!s) {
1478-
s = node->node()->suite();
1486+
s = n->suite();
14791487
}
14801488

14811489
if (s && s->begun()) {
1482-
node->node()->update_generated_variables();
1490+
n->update_generated_variables();
14831491
s->update_generated_variables();
14841492
}
14851493

@@ -1726,8 +1734,12 @@ QString VServer::toolTip() {
17261734
}
17271735
}
17281736

1729-
auto userLogHost = server_->conf()->stringValue(VServerSettings::UserLogServerHost);
1730-
auto userLogPort = server_->conf()->stringValue(VServerSettings::UserLogServerPort);
1737+
QString userLogHost;
1738+
QString userLogPort;
1739+
if (auto* conf = server_->conf(); conf) {
1740+
userLogHost = conf->stringValue(VServerSettings::UserLogServerHost);
1741+
userLogPort = conf->stringValue(VServerSettings::UserLogServerPort);
1742+
}
17311743
if (!userLogHost.isEmpty() && !userLogPort.isEmpty()) {
17321744
txt += "<br><b>Custom logserver</b>: " + userLogHost + "@" + userLogPort;
17331745
}

Viewer/ecflowUI/src/VServerSettings.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,40 @@ VServerSettings::~VServerSettings() {
106106
}
107107

108108
int VServerSettings::intValue(Param par) const {
109-
return property(par)->value().toInt();
109+
if (auto* p = property(par); p) {
110+
return p->value().toInt();
111+
}
112+
113+
return 0;
110114
}
111115

112116
bool VServerSettings::boolValue(Param par) const {
113-
return property(par)->value().toBool();
117+
if (auto* p = property(par); p) {
118+
return p->value().toBool();
119+
}
120+
121+
return false;
114122
}
115123

116124
QString VServerSettings::stringValue(Param par) const {
117-
return property(par)->value().toString();
125+
if (auto* p = property(par); p) {
126+
return p->value().toString();
127+
}
128+
129+
return {};
118130
}
119131

120132
VProperty* VServerSettings::property(Param par) const {
121-
auto it = parToProp_.find(par);
122-
if (it != parToProp_.end()) {
133+
if (auto it = parToProp_.find(par); it != parToProp_.end()) {
123134
return it->second;
124135
}
125-
else {
126-
assert(0);
127-
}
128136

137+
UiLog().err() << "VServerSettings::property - unknown parameter: " << par;
129138
return nullptr;
130139
}
131140

132141
void VServerSettings::notifyChange(VProperty* p) {
133-
auto it = propToPar_.find(p);
134-
if (it != propToPar_.end()) {
142+
if (auto it = propToPar_.find(p); it != propToPar_.end()) {
135143
server_->confChanged(it->second, it->first);
136144
}
137145
else {
@@ -140,10 +148,10 @@ void VServerSettings::notifyChange(VProperty* p) {
140148
}
141149

142150
std::string VServerSettings::notificationId(Param par) {
143-
auto it = notifyIds_.find(par);
144-
if (it != notifyIds_.end()) {
151+
if (auto it = notifyIds_.find(par); it != notifyIds_.end()) {
145152
return it->second;
146153
}
154+
147155
return {};
148156
}
149157

@@ -163,6 +171,7 @@ bool VServerSettings::notificationsEnabled() const {
163171
return true;
164172
}
165173
}
174+
166175
return false;
167176
}
168177

Viewer/ecflowUI/src/VServerSettings.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,30 @@ class VServerSettings : public VPropertyObserver {
5454
UserLogServerPort
5555
};
5656

57+
///
58+
/// @brief Access the associated integer value of the given parameter.
59+
///
60+
/// @param par The parameter for which to retrieve the integer value.
61+
/// @return The integer value for the given parameter, or 0 if the parameter is not found/not an integer.
62+
///
5763
int intValue(Param par) const;
64+
65+
///
66+
/// @brief Access the associated boolean value of the given parameter.
67+
///
68+
/// @param par The parameter for which to retrieve the boolean value.
69+
/// @return The boolean value for the given parameter, or false if the parameter is not found/not a boolean.
70+
///
5871
bool boolValue(Param par) const;
72+
73+
///
74+
/// @brief Access the associated string value of the given parameter.
75+
///
76+
/// @param par The parameter for which to retrieve the string value.
77+
/// @return The string value for the given parameter, or an empty string if the parameter is not found/not a string.
78+
///
5979
QString stringValue(Param par) const;
80+
6081
VProperty* guiProp() const { return guiProp_; }
6182
bool notificationsEnabled() const;
6283
static std::string notificationId(Param);
@@ -76,6 +97,12 @@ class VServerSettings : public VPropertyObserver {
7697
explicit VServerSettings(ServerHandler* server);
7798
~VServerSettings() override;
7899

100+
///
101+
/// @brief Access the property associated with the given parameter.
102+
///
103+
/// @param par The parameter for which to retrieve the property.
104+
/// @return The property associated with the parameter; or nullptr, if parameter is not found
105+
///
79106
VProperty* property(Param par) const;
80107
void loadSettings();
81108

Viewer/ecflowUI/src/VariableModelData.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,19 @@ bool VariableModelData::isGenVar(int index) const {
293293
return (index >= static_cast<int>(vars_.size()));
294294
}
295295

296-
bool VariableModelData::isMirrorVar(int index) const {
297-
return info_->isNode() && info_->node()->node()->isMirror();
296+
bool VariableModelData::isMirrorVar([[maybe_unused]] int index) const {
297+
if (!info_ || !info_->isNode()) {
298+
return false;
299+
}
300+
auto vnode = info_->node();
301+
if (!vnode) {
302+
return false;
303+
}
304+
auto node = vnode->node();
305+
if (!node) {
306+
return false;
307+
}
308+
return node->isMirror();
298309
}
299310

300311
bool VariableModelData::isGenVar(const std::string& n) const {

Viewer/libViewer/src/DirectoryHandler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,19 @@ void DirectoryHandler::init(const std::string& exeStr) {
116116
// will use the value of the ECFLOW_SHARED_DIR macro to get
117117
// the location of the "share/ecflow" dir.
118118
if (!fs::exists(exePath)) {
119-
fs::path shareDir(ECFLOW_SHARED_DIR);
119+
fs::path shareDir;
120+
if (auto* var = getenv("ECFLOW_SHARED_DIR"); var) {
121+
shareDir = var;
122+
UiLog().warn() << "Executable path does not exist. Used ECFLOW_SHARED_DIR env variable to find share dir: "
123+
<< shareDir.c_str();
124+
}
125+
else {
126+
shareDir = ECFLOW_SHARED_DIR;
127+
UiLog().warn()
128+
<< "Executable path does not exist. Used default ECFLOW_SHARED_DIR location to find share dir: "
129+
<< shareDir.c_str();
130+
}
131+
120132
if (!fs::exists(shareDir)) {
121133
UserMessage::message(
122134
UserMessage::ERROR,

0 commit comments

Comments
 (0)