Author Topic: Thousands of Callbacks  (Read 211 times)

K Fisher

  • Posts: 2
Thousands of Callbacks
« on: 15 Aug '17 - 21:18 »
To solve another problem I was having with AUTO_FREE, I
rewrote my code to Call BASS_StreamFree when I get an END
callback, thereby freeing the resources as soon as the stream
was finished.

Here is what I found:

Scenerio 1:
1) Create a stream with default options (no AUTO_FREE)
2) Set callbacks for END and FREE
3) Play the stream
When the Stream ends, I get an END call back, and I call BASS_StreamFree(channel)
I then get a FREE call back, everything appears to be OK
If I then repeat steps 1-3, I immediatly get an END callback
with Channel == 0 and Handle is a positive number (Note: Stream is still playing)
After the stream completes, I start getting thousands of END
callbacks with Channel == 0, Handle is a positive number

If I stop and restart my program, I get the same results (works first time)

Scenerio 2:
1) Create a stream with default options (no AUTO_FREE)
2) Set callback for END.  (Note: no callback for FREE)
3) Play the stream
When the stream ends, I get an END Callback, and I call BASS_StreamFree(channel)
Then I get multiple (4-7) End callbacks with the correct channel,
but a positive number for the Handle
After a few of these, Then I get thousands of END call backs
with Channel == 0, but a different positive number for the Handle.

Something is wierd, I am not doing anything fancy, just basic stuff.
I feel I am pretty proficent with Bass.lib, and have been working
with it for 3-4 months, and have had great results!

I am running windows 7, 64 bit.  I tried rebooting, same results.
Bass.BASS_GetVersion() = 33819649

Any Ideas?



Here is my Code:

       static private SYNCPROC _myTestSyncProc = null;

        public static void KPFTester()
        {
            if (_myTestSyncProc == null)
            {
                _myTestSyncProc = new SYNCPROC(EndSyncCallback);
            }
            //  Play Frog Croaking - length is about 5 seconds    --    note: BASS_STREAM_AUTOFREE
            string FrogFileName = @"d:\etc\sounds\Frog Croaking.mp3";

             int FrogStream = Bass.BASS_StreamCreateFile(FrogFileName, 0L, 0L, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE);
            //  set sync callbacks for both FREE and END
            Bass.BASS_ChannelSetSync(FrogStream, BASSSync.BASS_SYNC_FREE | BASSSync.BASS_SYNC_MIXTIME, 0, _myTestSyncProc, new IntPtr(55));
            Bass.BASS_ChannelSetSync(FrogStream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _myTestSyncProc, new IntPtr(166));
            Bass.BASS_ChannelPlay(FrogStream, false);
            SafeAddToListbox(DateTime.Now.ToString("mm:ss") + "  Starting Frog: " + FrogStream.ToString());
        }


        static int cCount=0;
        private static void EndSyncCallback(int handle, int channel, int data, IntPtr user)
        {
            int code = (int)user;
            string reason = "???";
            if (code == 55) reason = "FREE";
            if (code == 66) reason = "END";
            if (code == 166) reason = "END";
            if (code == 77) reason = "SLIDE";
       //     if (++cCount > 10) return;
            SafeAddToListbox(DateTime.Now.ToString("mm:ss") + " In Callback Reason: " + reason + " Channel = "+channel.ToString() + " Handle = " + handle.ToString());
            if (code == 166)
            {
                if (channel != 0)
                {
                    if (handle < 0)
                    {
                        SafeAddToListbox(DateTime.Now.ToString("mm:ss") + " Calling Bass.BASS_StreamFree" + " Channel = " + channel.ToString());
                        Bass.BASS_StreamFree(channel); //  BASS_StreamFree in the BASS_SYNC_END sync's callback.
                    }
                }
                else
                {
                    SafeAddToListbox(DateTime.Now.ToString("mm:ss") + " Channel == 0" + " Channel = " + channel.ToString());
                }
            }
        }

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Thousands of Callbacks
« Reply #1 on: 16 Aug '17 - 15:38 »
I should have mentioned in my reply to your other post that the BASS_SYNC_END sync should not be "mixtime" (I have now edited the reply). That will ensure that the stream is fully heard before it's freed, but more importantly, it is unsafe to free a stream within its own "mixtime" SYNCPROC. The latter may be what's causing the strange behaviour that you have described; let me know if you still get it even after removing the BASS_SYNC_MIXTIME flag.