garrysmod-issues icon indicating copy to clipboard operation
garrysmod-issues copied to clipboard

IGModAudioChannel Stop() also deletes object

Open neico opened this issue 10 years ago • 5 comments

As of #278 Stop() simply kills the entire channel, this however should be up to __GC() to do.

the BASS instance can be destroyed but shouldn't affect the lua instance, since this behavior makes playing streams more complicated. (As you'd need to check for IsValid more often and then re-create the instance after each Stop() call)

If you use Pause() on a stream it'll just de-sync and will be behind for as long as it's paused, this is undesired behavior most of the time.

Solutions:

  1. Handle Stop() differently, keeping the lua instance until actually destroyed trough __GC(), so that Play recreates the BASS instance and plays again... (recommended)
  2. Make Pause() watch out for streams and give a hint to Play() to re-fetch the stream before playing again (as optional arument to keep both worlds happy)
  3. Restore Stop()'s old behavior and add a Kill() / Destroy() function to take over the new behavior (not recommended as this messes with people expecting above behavior from Stop() by now)

neico avatar Sep 13 '14 20:09 neico

It is kind off intended. I wrote the developers about using __GC() properly before, but they don't like it much. They use Stop() as a replacement for it. They want you to be able to do this: sound.PlayURL("http://inter.net/somesound.mp3") without having to care about the callback or its channel object.

Grocel avatar Sep 20 '14 22:09 Grocel

Hi. In order to avoid compatibility problems with older addons, the third solution is of course the best one.

The new Stop() behavior can be bound in Lua as IGModAudioChannel:Remove(), that is a good idea. To substitude the old behavior, I suggest that IGModAudioChannel:Stop() should do IGModAudioChannel:Pause() then IGModAudioChannel:SetTime( 0 ). It even works well for block-streamed sounds, so I think it should be safe.

EstevanTH avatar Oct 02 '16 01:10 EstevanTH

Bump #2977 Added warning to wiki.

mandrewpowers avatar Dec 20 '16 11:12 mandrewpowers

It's been two years, any hope for a fix? CSoundPatch is even buggier than the newer IGModAudioChannel so this is all we have for decent audio playback.

looterz avatar Feb 19 '17 05:02 looterz

Seems Stop() also causes the IsValid() function to become nil?

https://github.com/thegrb93/StarfallEx/pull/1252

thegrb93 avatar Jan 10 '22 21:01 thegrb93