GameMaker [SOLVED]Async event not firing after loading audio group.

S

StarSoul

Guest
Hi, I am new to the forums and I come here because I have a problem. No matter what I do, I cannot get the audio to work for my game. If it matters, I am on a Mac OS X. Here is my code:

Code:
obj_mus > create event > 
audio_group_load(audiogroup_default);

obj_mus > async Save/Load event > 
audio_play_sound(snd_voice_0,10,true);
Simple, right? I even consulted many tutorials before this, but it's still not working. The object is in the room, snd_voice_0 is in audiogroup_default, snd_voice_0 plays in the sound viewer, but all I get is silence.

Any help would be appreciated. Thank you in advance.
-StarSoul
 

samspade

Member
Hi, I am new to the forums and I come here because I have a problem. No matter what I do, I cannot get the audio to work for my game. If it matters, I am on a Mac OS X. Here is my code:

Code:
obj_mus > create event >
audio_group_load(audiogroup_default);

obj_mus > async Save/Load event >
audio_play_sound(snd_voice_0,10,true);
Simple, right? I even consulted many tutorials before this, but it's still not working. The object is in the room, snd_voice_0 is in audiogroup_default, snd_voice_0 plays in the sound viewer, but all I get is silence.

Any help would be appreciated. Thank you in advance.
-StarSoul
It's been awhile since I've set this stuff up, but that doesn't look right to me. The first part, your create event is fine, and the second part should play once, unless async events don't allow sounds to be played which they might not, but that isn't how you play sounds. I'm also pretty sure that the audiogroup_default automatically loads and you don't need to do anything with it. You only need to load in your own custom groups. You don't even 'need to' do the async event, as, in this case, it just checks to make sure the group is loaded, though you should to prevent errors. My basic set up looks like this:

Code:
/// create event of my audio controller
audio_group_load(music);

/// async event of my audio controller
if (audio_group_is_loaded(music)) {
    MUSIC_LOADED = true;
}

///another object - simplified from the actual code
if (MUSIC_LOADED == true) {
    room_goto(next);
}
Essentially, my music controller is created in an 'initialize room' (a blank room with a number of objects that set up some basic stuff such as music) at the start of the game and loads in all my audio groups - music group shown here as an example. The async event checks to see if it has loaded and if it has sets a global variable to true. My main controller object is checking a variety of things (in this case simplified to just music) and when they are all true, it goes to the next room which is the start of the game. And I don't play any sounds in my initialize room. Once the group is loaded, you can just call play sound whenever you want.

EDIT: Just checked, async will play sounds however, it does not fire for loading the default audio group. Only custom audio groups. Mostly likely because you don't need to, and maybe even can't, load the default audio group yourself.
 
S

StarSoul

Guest
It's been awhile since I've set this stuff up, but that doesn't look right to me. The first part, your create event is fine, and the second part should play once, unless async events don't allow sounds to be played which they might not, but that isn't how you play sounds. I'm also pretty sure that the audiogroup_default automatically loads and you don't need to do anything with it. You only need to load in your own custom groups. You don't even 'need to' do the async event, as, in this case, it just checks to make sure the group is loaded, though you should to prevent errors. My basic set up looks like this:

Code:
/// create event of my audio controller
audio_group_load(music);

/// async event of my audio controller
if (audio_group_is_loaded(music)) {
    MUSIC_LOADED = true;
}

///another object - simplified from the actual code
if (MUSIC_LOADED == true) {
    room_goto(next);
}
Essentially, my music controller is created in an 'initialize room' (a blank room with a number of objects that set up some basic stuff such as music) at the start of the game and loads in all my audio groups - music group shown here as an example. The async event checks to see if it has loaded and if it has sets a global variable to true. My main controller object is checking a variety of things (in this case simplified to just music) and when they are all true, it goes to the next room which is the start of the game. And I don't play any sounds in my initialize room. Once the group is loaded, you can just call play sound whenever you want.

EDIT: Just checked, async will play sounds however, it does not fire for loading the default audio group. Only custom audio groups. Mostly likely because you don't need to, and maybe even can't, load the default audio group yourself.
I copied and pasted your code into a new program, and I found out a few things.

If I have
Code:
/// create event 
MUSIC_LOADED=false;
audio_group_load(soundeffects);
it will not load, because if I then do...
Code:
/// async event 
if (audio_group_is_loaded(audiogroup_default)) {
   MUSIC_LOADED = true;
}
MUSIC_LOADED will equal to true, allowing the other object to take me to the next room. Another interesting thing I noticed is that if I have more than one sound file under >Sounds, Gamemaker crashes with this error log:

Process: Mac_Runner [1608]
Path: /Users/Shared/*/YoYo Runner.app/Contents/MacOS/Mac_Runner
Identifier: com.yoyogames.macyoyorunner
Version: 2.2.287 (2.2.287)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Mac_Runner [1608]
User ID: 502

Date/Time: 2019-01-01 14:11:43.520 -0600
OS Version: Mac OS X 10.11.6 (15G19009)
Report Version: 11
Anonymous UUID: 4CAEED1C-EEE4-9825-E98A-0F74AF256BA4


Time Awake Since Boot: 8800 seconds

System Integrity Protection: disabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007f91c35c0b60
Exception Note: EXC_CORPSE_NOTIFY

VM Regions Near 0x7f91c35c0b60:
MALLOC_SMALL 00007f9175000000-00007f9177000000 [ 32.0M] rw-/rwx SM=PRV
-->
STACK GUARD 00007fff579ca000-00007fff5b1ca000 [ 56.0M] ---/rwx SM=NUL stack guard for thread 0

I'm really not sure what's wrong, if it's my computer or somehow it's Gamemaker, or if I'm behind on an update or something.
 

samspade

Member
I don't understand your comment. You say if you do A, it (the game?) will not load because if you then do B, X will always be true. That doesn't make a lot of sense.

I can't say for sure, because I don't have all your code in front of me, but you might need to be more careful in how you read and understand other people's code. At a minimum, the code you posted here doesn't follow my code as you tell it to load soundeffects but then set MUSIC_LOADED by checking if the audiogroup_default is loaded and, as I pointed out in my original post, the async event doesn't fire for the default audiogroup. Now this might work anyway as it should fire when soundeffects is loaded and assuming the default audiogroup is loaded by the time it happens, that will still return true, but this is still bad and I'm not sure what would happen if soundeffects was loaded first or if GM doesn't allow you to check the default audiogroup with that function.

I've never received that error message before and I use windows so I might not be able to help. It looks like it is some sort of thread error which I basically know nothing about beyond GM is single threaded except for a few specific things like audio, which implies that something in your code is causing an error in how GM is relating to the audio thread, but that's just a guess. You might have to google it, but I would try to fix the original problem first as this other problem might be a secondary result of your code not being correct.
 
S

StarSoul

Guest
Okay. I think I figured it out. I tested the code on Windows, GMS2 version 2.2.1.291 and it seems to work. My only guess is that something happened with GMS2 on my Mac and I might need to re-install. I will test this theory later. Thank you for the help, Samspade, and I hope this helps someone in the future!
 
Top