Skip to content

Commit

Permalink
Fix infinite recursion on setting boiol user options.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Oct 22, 2024
1 parent 158923f commit b1cc3f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion InterSpec/UserPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ class UserPreferences : public Wt::WObject
const double &value,
InterSpec *viewer );

static void setPreferenceValueWorker( const std::string &name,
/** Does the work of setting the preference value.
@returns if the value was updated or not (e.g. same value as before).
*/
static bool setPreferenceValueWorker( const std::string &name,
std::string value_as_string,
InterSpec *viewer );

Expand Down
4 changes: 2 additions & 2 deletions src/InterSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11984,10 +11984,10 @@ void InterSpec::handleAppUrl( const std::string &url_encoded_url )
if( m_simpleMdaWindow )
prev_state = m_simpleMdaWindow->tool()->encodeStateToUrl();

auto create_window = [this, query_str](){
auto create_window = [this, url](){
DetectionLimitSimpleWindow *tool = showSimpleMdaWindow();
if( tool )
tool->tool()->handleAppUrl( query_str );
tool->tool()->handleAppUrl( url );
};//create_window lambda

if( m_undo && m_undo->canAddUndoRedoNow() )
Expand Down
22 changes: 16 additions & 6 deletions src/UserPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,22 @@ void UserPreferences::setPreferenceValueInternal( const std::string &name,
InterSpec *viewer )
{
const string value_as_str = value ? "1" : "0";
UserPreferences::setPreferenceValueWorker( name, value_as_str, viewer );
const bool updated = UserPreferences::setPreferenceValueWorker( name, value_as_str, viewer );

// If preference value was not updated, we wont call the callbacks - if we do, we may get stuck
// in an infinite recursion loop.
if( !updated )
return;

UserPreferences * const self = viewer->preferences();
assert( self );

const auto callback_pos = self->m_onBoolChangeSignals.find(name);
if( (callback_pos != end(self->m_onBoolChangeSignals)) && callback_pos->second )
(*callback_pos->second)(value);
{
Wt::Signals::signal<void(bool)> &signal = *callback_pos->second;
signal(value);
}
}//setPreferenceValueInternal(...)


Expand Down Expand Up @@ -410,7 +418,7 @@ void UserPreferences::setPreferenceValueInternal( const std::string &name,



void UserPreferences::setPreferenceValueWorker( const std::string &name,
bool UserPreferences::setPreferenceValueWorker( const std::string &name,
std::string value_as_string,
InterSpec *viewer )
{
Expand All @@ -426,7 +434,7 @@ void UserPreferences::setPreferenceValueWorker( const std::string &name,
assert( self );
auto old_pos = self->m_options.find(name);
if( (old_pos != end(self->m_options)) && (old_pos->second->m_value == value_as_string) )
return;
return false;

std::shared_ptr<DataBaseUtils::DbSession> sql = viewer->sql();
const Wt::Dbo::ptr<InterSpecUser> &user = viewer->user();
Expand Down Expand Up @@ -461,12 +469,12 @@ void UserPreferences::setPreferenceValueWorker( const std::string &name,
std::cerr << "Caught exception setting preference value to database" << std::endl;
}

return;
return true;
}//if( old_pos != end(self->m_options) )


// If we are here, we dont have a value in memory so we'll check if its been added
// to the database since we initialized this session, and if not, we'll start with'
// to the database since we initialized this session, and if not, we'll start with
// default value
DataBaseUtils::DbTransaction transaction( *sql );

Expand Down Expand Up @@ -511,6 +519,8 @@ void UserPreferences::setPreferenceValueWorker( const std::string &name,
}//if( optioncol.size() >= 1 ) / else

transaction.commit();

return true;
}//setPreferenceValueWorker(...)


Expand Down

0 comments on commit b1cc3f4

Please sign in to comment.