Don't free channels at library unloading, it crashes. Do that in the '_exit' method of the Channel class.

[GB.SDL2.AUDIO]
* BUG: Don't free channels at library unloading, it crashes. Do that in the '_exit' method of the Channel class.
This commit is contained in:
gambas 2018-04-11 03:43:18 +02:00
parent de12caa1e7
commit 78ac58fb48
2 changed files with 27 additions and 20 deletions

View file

@ -183,7 +183,7 @@ void CHANNEL_exit()
continue;
free_channel(ch);
GB.Unref(POINTER(&ch));
GB.Unref(POINTER(&_cache[i]));
}
if (_pipe_usage)
@ -262,6 +262,12 @@ BEGIN_METHOD_VOID(Channel_new)
END_METHOD
BEGIN_METHOD_VOID(Channel_exit)
CHANNEL_exit();
END_METHOD
BEGIN_METHOD(Channel_Play, GB_OBJECT sound; GB_INTEGER loops; GB_FLOAT fadein)
CSOUND *sound;
@ -387,7 +393,7 @@ GB_DESC ChannelDesc[] =
GB_METHOD("_new", NULL, Channel_new, NULL),
//GB_STATIC_METHOD("_exit", NULL, Channel_exit, NULL),
GB_STATIC_METHOD("_exit", NULL, Channel_exit, NULL),
GB_METHOD("Play", NULL, Channel_Play, "[(Sound)Sound;(Loops)i(FadeIn)f]"),
GB_METHOD("Pause", NULL, Channel_Pause, NULL),
GB_METHOD("Stop", NULL, Channel_Stop, "[(FadeOut)f]"),

View file

@ -1,23 +1,23 @@
/***************************************************************************
main.c
main.c
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
@ -71,7 +71,7 @@ bool AUDIO_init()
return TRUE;
}
Mix_QuerySpec(&AUDIO_frequency, &format, &channels);
Mix_QuerySpec(&AUDIO_frequency, &format, &channels);
//fprintf(stderr, "AUDIO_init: %d %d %d\n", AUDIO_frequency, format, channels);
if (CHANNEL_init())
@ -86,9 +86,10 @@ static void AUDIO_exit()
if (!AUDIO_initialized)
return;
CHANNEL_exit();
MUSIC_exit();
Mix_CloseAudio();
// Don't free Gambas objects from GB_EXIT!
// CHANNEL_exit();
MUSIC_exit();
Mix_CloseAudio();
while (Mix_Init(0))
Mix_Quit();