Skip to content

Commit

Permalink
fix crash on keybind reset in UILIST context etc.
Browse files Browse the repository at this point in the history
 - The crash occured in all contexts where there were no defaults. UILIST is one of them.
  • Loading branch information
Brambor committed Nov 28, 2024
1 parent ad13310 commit c460baa
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/input_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,13 +849,16 @@ bool input_context::action_reset( const std::string &action_id )
std::vector<input_event> conflicting_events;
std::array<std::reference_wrapper<const std::string>, 2> contexts = { default_context_id, category };
for( const std::string &context : contexts ) {
const input_manager::t_actions &def = inp_mngr.basic_action_contexts.at( context );

bool is_in_def = def.find( action_id ) != def.end();
if( is_in_def ) {
for( const input_event &event : def.at( action_id ).input_events ) {
conflicting_events.emplace_back( event );
}
auto iter_basic = inp_mngr.basic_action_contexts.find( context );
if( iter_basic == inp_mngr.basic_action_contexts.end() ) {
continue;
}
auto iter_action = iter_basic->second.find( action_id );
if( iter_action == iter_basic->second.end() ) {
continue;
}
for( const input_event &event : iter_action->second.input_events ) {
conflicting_events.emplace_back( event );
}
}
if( !resolve_conflicts( conflicting_events, action_id ) ) {
Expand All @@ -864,20 +867,25 @@ bool input_context::action_reset( const std::string &action_id )

// RESET KEY BINDINGS
for( const std::string &context : contexts ) {
const input_manager::t_actions &def = inp_mngr.basic_action_contexts.at( context );
const input_manager::t_actions &cus = inp_mngr.action_contexts.at( context );

bool is_in_def = def.find( action_id ) != def.end();
bool is_in_cus = cus.find( action_id ) != cus.end();

if( is_in_cus ) {
inp_mngr.remove_input_for_action( action_id, context );
// reset -> remove from user created keybindings
auto iter_cus = inp_mngr.action_contexts.find( context );
if( iter_cus != inp_mngr.action_contexts.end() ) {
if( iter_cus->second.find( action_id ) != iter_cus->second.end() ) {
inp_mngr.remove_input_for_action( action_id, context );
}
}

if( is_in_def ) {
for( const input_event &event : def.at( action_id ).input_events ) {
inp_mngr.add_input_for_action( action_id, context, event );
}
// reset the original keybindings
auto iter_def = inp_mngr.basic_action_contexts.find( context );
if( iter_def == inp_mngr.basic_action_contexts.end() ) {
continue;
}
auto iter_action = iter_def->second.find( action_id );
if( iter_action == iter_def->second.end() ) {
continue;
}
for( const input_event &event : iter_action->second.input_events ) {
inp_mngr.add_input_for_action( action_id, context, event );
}
}
return true;
Expand Down

0 comments on commit c460baa

Please sign in to comment.