Velorexe / Unity-Android-Bluetooth-Low-Energy

A Unity Android plugin to support basic Bluetooth Low Energy interactions.
The Unlicense
101 stars 21 forks source link

Risk of skipping a command when clearing parallel stack? #54

Closed Cnaits closed 5 months ago

Cnaits commented 5 months ago

I think in the BleManager's OnBleMessageReceived when the parallel Stack is cleared of consumed items the list should either be iterated over in reverse, or i decremented whenever an item is removed:

// Run through the parallel stack, remove the commands that have consumed the BleObject
for (int i = _parallelStack.Count - 1; i >= 0; i--)
{
    if (_parrallelStack[i].CommandReceived(obj))
    {
        _parrallelStack[i].End();
        _parrallelStack.RemoveAt(i);
    }
}

or

// Run through the parallel stack, remove the commands that have consumed the BleObject
for (int i = 0; i < _parrallelStack.Count; i++)
{
    if (_parrallelStack[i].CommandReceived(obj))
    {
        _parrallelStack[i].End();
        _parrallelStack.RemoveAt(i);
        i--;
    }
}
Cnaits commented 5 months ago

Sorry, I missed the project overhaul branch. Doesn't seem to be a problem there.