Skip to content

Commit b4a23f5

Browse files
committed
Potentially fix some issues loading app states.
This was motivated by a user report of app getting into a state where the app became unusable, due to loading an invalid state - however, I dont know if this work will actually fix the issue. The issue was happening in JS, however, I think the JS error was related to a c++ exception causing not everything to be loaded. I was able to Have not fixed all potential issues. Made so InterSpec::loadState c++ has more granular try/catchs, and tried re-arranging order of operations a little so changes to the GUI isnt as intertwined with the DB code, although this is still the case to a good extent. Fixed issue of loading Act/Shield state that could cause inconsistencies, due to checks being applied to GUI state before it was fully deserialized. Also added some JS try/catch around the spectrum calls to JS, since this is where the error showed up, but adding these protections are unlikely to be very useful.
1 parent 3604105 commit b4a23f5

File tree

7 files changed

+272
-205
lines changed

7 files changed

+272
-205
lines changed

InterSpec/InterSpecApp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ class InterSpec_API InterSpecApp : public Wt::WApplication
266266
/** Adds `m_activeTimeSinceDbUpdate` to the database, saving the updated result. */
267267
void updateUsageTimeToDb();
268268

269-
#if( BUILD_AS_WX_WIDGETS_APP )
270269
virtual void handleJavaScriptError( const std::string &errorText );
271-
#endif
272270

273271
#if( !BUILD_FOR_WEB_DEPLOYMENT )
274272
/** Checks for URL argument "externalid", or equivalently "apptoken", and if found sets m_externalToken to it.

InterSpec/InterSpecUser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ struct UserState
770770
int backgroundId;
771771
int secondForegroundId;
772772
int shieldSourceModelId;
773-
std::string otherSpectraCsvIds;
773+
std::string otherSpectraCsvIds; //!< TODO: This doesnt look to be used; should add option to save all other open files to the database when saving a state; noting which are part of saved app states or not
774774
std::string foregroundSampleNumsCsvIds;
775775
std::string secondForegroundSampleNumsCsvIds;
776776
std::string backgroundSampleNumsCsvIds;

InterSpec/ShieldingSourceDisplay.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,9 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
372372
373373
@param before If nullptr, the shielding will be added after the last ShieldingSelect; if non-null, the new ShieldingSelect will be added
374374
before the specified ShieldingSelect.
375-
@param updateChiChartAndAddUndoRedo If true, the Chi2 chart will be updated after adding, AND a undo/redo point will be
376-
added.
375+
@param addUndoRedo If true, an undo/redo point will be added.
377376
*/
378-
ShieldingSelect *addShielding( ShieldingSelect *before, const bool updateChiChartAndAddUndoRedo );
377+
ShieldingSelect *addShielding( ShieldingSelect *before, const bool addUndoRedo );
379378

380379
//doAddShielding(), doAddShieldingBefore(), doAddShieldingAfter:
381380
// convience functions that calls addShielding(...) appropriately.
@@ -468,9 +467,17 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
468467
// std::exception on error, with a message approprtiate for output to user.
469468
void checkAndWarnZeroMassFraction();
470469

471-
//checkDistanceAndThicknessConsistent(): called when the m_distanceEdit is
472-
// changed; makes sure radius of outer shielding is less than this distnace,
473-
// and updates chi2 chart
470+
/** Called when doing a model fit, the geometry changes, or when updating the Chi2 chart due to dimension or
471+
shielding/material changes (this update happens during the `Wt::render(...)` call), to make sure radius of
472+
outer shielding is less than the detector distance, and other characteristics of the shielding are consistent with the
473+
model.
474+
This function also updates the fit model activities of for volumetric sources.
475+
476+
Note: this function should only be called when the whole GUI state is completely setup.
477+
For example, if you first set shielding thicknesses, then call this function, then set detector distance, you
478+
could have caused the shielding thicknesses to have been changed based on the old detector distances.
479+
This also applies to other properties like which thicknesses are allowed to be fit.
480+
*/
474481
void checkDistanceAndThicknessConsistent();
475482

476483
/** Checks to see if fitting for more than one atomic number of generic shielding.

src/D3SpectrumDisplayDiv.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void D3SpectrumDisplayDiv::setShowPeakLabel( int label, bool show )
577577
{
578578
SpectrumChart::PeakLabels peakLabel = SpectrumChart::PeakLabels(label);
579579

580-
string js = m_jsgraph;
580+
string js = "try{" + m_jsgraph;
581581
switch( peakLabel )
582582
{
583583
case SpectrumChart::PeakLabels::kShowPeakUserLabel:
@@ -598,6 +598,7 @@ void D3SpectrumDisplayDiv::setShowPeakLabel( int label, bool show )
598598
break;
599599
}
600600
js += "(" + jsbool(show) + ");";
601+
js += "}catch(e){ console.error('Error showing peak labels:',e); }";
601602

602603
m_peakLabelsToShow[peakLabel] = show;
603604

@@ -711,8 +712,16 @@ void D3SpectrumDisplayDiv::clearAllReferncePhotoPeakLines()
711712
m_persistedPhotoPeakLines.clear();
712713

713714
if( isRendered() )
714-
doJavaScript(m_jsgraph + ".clearReferenceLines();");
715-
}
715+
{
716+
// Will add try/catch to this call as a debug measure, for a problem in another location
717+
doJavaScript(
718+
"try{"
719+
+ m_jsgraph + ".clearReferenceLines();"
720+
"}catch(e){"
721+
"console.error('Error clearing ref lines',e);"
722+
"}");
723+
}//if( isRendered() )
724+
}//void clearAllReferncePhotoPeakLines()
716725

717726

718727
void D3SpectrumDisplayDiv::setReferenceLinesToClient()
@@ -937,23 +946,44 @@ void D3SpectrumDisplayDiv::showGridLines( bool show )
937946
m_showVerticalLines = show;
938947
m_showHorizontalLines = show;
939948
if( isRendered() )
940-
doJavaScript( m_jsgraph + ".setGridX(" + jsbool(show) + ");"
941-
+ m_jsgraph + ".setGridY(" + jsbool(show) + ");" );
942-
}
949+
{
950+
doJavaScript(
951+
"try{"
952+
+ m_jsgraph + ".setGridX(" + jsbool(show) + ");"
953+
+ m_jsgraph + ".setGridY(" + jsbool(show) + ");"
954+
"}catch(e){"
955+
"console.error('showGridLines error:',e);"
956+
"}");
957+
}
958+
}//showGridLines(...)
943959

944960
void D3SpectrumDisplayDiv::showVerticalLines( const bool draw )
945961
{
946962
m_showVerticalLines = draw;
947963
if( isRendered() )
948-
doJavaScript( m_jsgraph + ".setGridX(" + jsbool(draw) + ");" );
949-
}
964+
{
965+
doJavaScript(
966+
"try{"
967+
+ m_jsgraph + ".setGridX(" + jsbool(draw) + ");"
968+
"}catch(e){"
969+
"console.error('showVerticalLines error:',e);"
970+
"}" );
971+
}
972+
}//showVerticalLines( const bool draw )
950973

951974
void D3SpectrumDisplayDiv::showHorizontalLines( const bool draw )
952975
{
953976
m_showHorizontalLines = draw;
954977
if( isRendered() )
955-
doJavaScript( m_jsgraph + ".setGridY(" + jsbool(draw) + ");" );
956-
}
978+
{
979+
doJavaScript(
980+
"try{"
981+
+ m_jsgraph + ".setGridY(" + jsbool(draw) + ");"
982+
"}catch(e){"
983+
"console.error('showHorizontalLines error:',e);"
984+
"}" );
985+
}
986+
}//showHorizontalLines( const bool draw )
957987

958988
bool D3SpectrumDisplayDiv::verticalLinesShowing() const
959989
{

0 commit comments

Comments
 (0)