Merge pull request #9674 from Filoppi/fix_hotkey_suppresion_crash
Fix hotkey suppression crash
This commit is contained in:
commit
1daefeb20a
|
@ -64,7 +64,7 @@ private:
|
||||||
void RemoveSuppression(Device::Input* modifier, Device::Input* final_input)
|
void RemoveSuppression(Device::Input* modifier, Device::Input* final_input)
|
||||||
{
|
{
|
||||||
auto it = m_suppressions.find({final_input, modifier});
|
auto it = m_suppressions.find({final_input, modifier});
|
||||||
if ((--it->second) == 0)
|
if (it != m_suppressions.end() && (--it->second) == 0)
|
||||||
m_suppressions.erase(it);
|
m_suppressions.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ bool HotkeySuppressions::IsSuppressedIgnoringModifiers(Device::Input* input,
|
||||||
|
|
||||||
// We need to ignore L_Ctrl R_Ctrl when supplied Ctrl and vice-versa.
|
// We need to ignore L_Ctrl R_Ctrl when supplied Ctrl and vice-versa.
|
||||||
const auto is_same_modifier = [](Device::Input* i1, Device::Input* i2) {
|
const auto is_same_modifier = [](Device::Input* i1, Device::Input* i2) {
|
||||||
return i1 == i2 || i1->IsChild(i2) || i2->IsChild(i1);
|
return i1 && i2 && (i1 == i2 || i1->IsChild(i2) || i2->IsChild(i1));
|
||||||
};
|
};
|
||||||
|
|
||||||
return std::any_of(it, it_end, [&](auto& s) {
|
return std::any_of(it, it_end, [&](auto& s) {
|
||||||
|
@ -317,7 +317,13 @@ HotkeySuppressions::MakeSuppressor(const Modifiers* modifiers,
|
||||||
const std::unique_ptr<ControlExpression>* final_input)
|
const std::unique_ptr<ControlExpression>* final_input)
|
||||||
{
|
{
|
||||||
for (auto& modifier : *modifiers)
|
for (auto& modifier : *modifiers)
|
||||||
++m_suppressions[{(*final_input)->GetInput(), modifier->GetInput()}];
|
{
|
||||||
|
// Inputs might be null, don't add nullptr to the map
|
||||||
|
if ((*final_input)->GetInput() && modifier->GetInput())
|
||||||
|
{
|
||||||
|
++m_suppressions[{(*final_input)->GetInput(), modifier->GetInput()}];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Suppressor(std::make_unique<std::function<void()>>([this, modifiers, final_input]() {
|
return Suppressor(std::make_unique<std::function<void()>>([this, modifiers, final_input]() {
|
||||||
for (auto& modifier : *modifiers)
|
for (auto& modifier : *modifiers)
|
||||||
|
@ -484,6 +490,7 @@ public:
|
||||||
|
|
||||||
ControlState GetValue() const override
|
ControlState GetValue() const override
|
||||||
{
|
{
|
||||||
|
// True if we have no modifiers
|
||||||
const bool modifiers_pressed = std::all_of(m_modifiers.begin(), m_modifiers.end(),
|
const bool modifiers_pressed = std::all_of(m_modifiers.begin(), m_modifiers.end(),
|
||||||
[](const std::unique_ptr<ControlExpression>& input) {
|
[](const std::unique_ptr<ControlExpression>& input) {
|
||||||
return input->GetValue() > CONDITION_THRESHOLD;
|
return input->GetValue() > CONDITION_THRESHOLD;
|
||||||
|
@ -497,7 +504,7 @@ public:
|
||||||
const bool is_suppressed = s_hotkey_suppressions.IsSuppressedIgnoringModifiers(
|
const bool is_suppressed = s_hotkey_suppressions.IsSuppressedIgnoringModifiers(
|
||||||
m_final_input->GetInput(), m_modifiers);
|
m_final_input->GetInput(), m_modifiers);
|
||||||
|
|
||||||
if (final_input_state < CONDITION_THRESHOLD)
|
if (final_input_state <= CONDITION_THRESHOLD)
|
||||||
m_is_blocked = false;
|
m_is_blocked = false;
|
||||||
|
|
||||||
// If some other hotkey suppressed us, require a release of final input to be ready again.
|
// If some other hotkey suppressed us, require a release of final input to be ready again.
|
||||||
|
@ -540,13 +547,13 @@ public:
|
||||||
|
|
||||||
// We must update our suppression with valid pointers.
|
// We must update our suppression with valid pointers.
|
||||||
if (m_suppressor)
|
if (m_suppressor)
|
||||||
EnableSuppression();
|
EnableSuppression(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EnableSuppression() const
|
void EnableSuppression(bool force = false) const
|
||||||
{
|
{
|
||||||
if (!m_suppressor)
|
if (!m_suppressor || force)
|
||||||
m_suppressor = s_hotkey_suppressions.MakeSuppressor(&m_modifiers, &m_final_input);
|
m_suppressor = s_hotkey_suppressions.MakeSuppressor(&m_modifiers, &m_final_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue