AudioChannel random Null pointer referenced error

Started by nightmarer, Tue 26/04/2022 22:51:19

Previous topic - Next topic

nightmarer

Hello all, long time no see.

I'm receiving a random error while setting SetRoomLocation method to an AudioChannel as soon as I enter in one room.
Error running function 'room_AfterFadeIn': Error: Null pointer referenced
The weirdest thing is that it happens one time every four times I enter in the room.
This is the code, and I just using it as it is refered in the manual.

Code: ags
//ROOM SCRIPT
AudioChannel *carBurning;

function room_AfterFadeIn(){
    carBurning = aExplosionroom_burningcar.Play();
    carBurning.SetRoomLocation(oCarFire.X, oCarFire.Y); //This is the row that the error points
}


BTW, if it works sometimes it just stops playing when another sound in the room is played (not using that AudioChannel)
BTW, I'm using AGS (Build 3.5.1.16)

Crimson Wizard

#1
If you read the manual:
https://adventuregamestudio.github.io/ags-manual/AudioClip.html#audioclipplay

Quote
If all audio channels are busy playing higher priority sounds, then this new audio clip will not be played.

This command returns the AudioChannel instance that the new sound is playing on, or null if it did not play for any reason.

Play() function may return null pointer if it was not able to play the sound for any reason. There are few reasons for this to happen:
* the sound is completely disabled by the user in config;
* sound failed to load;
* no free channel found (all busy). The usual case is when this sound type has limited reserved channels ("Max Channels" property set) and they have clips with higher priority playing.

So normally you should be checking for a null pointer:
Code: ags

if (carBurning)
    carBurning.SetRoomLocation(oCarFire.X, oCarFire.Y);



Quote from: nightmarer on Tue 26/04/2022 22:51:19
BTW, if it works sometimes it just stops playing when another sound in the room is played (not using that AudioChannel)

Thing is, you cannot tell which channel to play the sound on with Play(). Instead, the function searches for all available channels in the engine and finds a free one. If no free one is ready, then it replaces one of the playing sounds with same or lower priority.
Perhaps double check your Audio Types settings in the editor and see how many channels are reserved for the sounds. Maybe you may reserve more.
If you want certain sounds to be never replaced, make sure to Play it with higher priority.

Note that the total number of channels in AGS 3.5.1 is 8 (actually 7, because 1 is always reserved for voice-over).

nightmarer


SMF spam blocked by CleanTalk