adamk33n3r / runelite-watchdog

Custom notification plugin for RuneLite
BSD 2-Clause "Simplified" License
6 stars 24 forks source link

Multiple Infinitely Repeating Sounds get stuck forever #122

Closed CreativeTechGuy closed 9 months ago

CreativeTechGuy commented 9 months ago

Repro:

{
  "type": "PlayerChatAlert",
  "playerChatType": "ANY",
  "message": "*",
  "regexEnabled": false,
  "enabled": true,
  "name": "Test",
  "debounceTime": 0,
  "notifications": [
    {
      "type": "Sound",
      "path": "sound-1.wav",
      "repeatDuration": -1,
      "gain": 3,
      "fireWhenFocused": true,
      "fireWhenAFK": false,
      "fireWhenAFKForSeconds": 5
    },
    {
      "type": "Sound",
      "path": "sound-2.wav",
      "repeatDuration": -1,
      "gain": 3,
      "fireWhenFocused": true,
      "fireWhenAFK": false,
      "fireWhenAFKForSeconds": 5
    }
  ]
}

The alert above is the easiest way to reproduce this, but it can also occur if a repeatDuration: -1 sound exists in two different alerts that get triggered at the same time. What will happen is that both will play, the second one will stop, the first one will never be cancelled, regardless of what you do (including logging out, disabling the plugin, etc). The only way to recover is to completely close RuneLite.

adamk33n3r commented 9 months ago

Hmmmm...I wonder if it's because notifications are fired on their own thread. Might be a threading issue. Will probably have to put a lock on the playNext method of the player (I think that's what it's called). They're probably setting soundTimeout at the same time or some race condition. When you say the second one will stop do you mean it will stop when the first one plays? or that it will stop correctly after user interaction?

CreativeTechGuy commented 9 months ago

When you say the second one will stop do you mean it will stop when the first one plays? or that it will stop correctly after user interaction?

It'll stop correctly after user interaction. Although this seems to be inconsistent. Not sure exactly why, but sometimes all of the sounds that are looping cannot be canceled with user interaction, sometimes after user interaction one of them stops (seems like if that's the case, it's the last one which was triggered in order).

adamk33n3r commented 9 months ago

After doing some testing myself, it looks like this only happens if you're not using the sound queue

CreativeTechGuy commented 9 months ago

Ah good catch. Yeah I don't have the sound queue setting on. I didn't think of that. And the solution seems reasonable! Thank you :)