Possible engine bug with AudioChannel.Stop

Started by Grundislav, Yesterday at 20:10:25

Previous topic - Next topic

Grundislav

Hello,

I've found a bug that seems to have no explanation. I suspect there might be something wrong with AudioChannel.Stop.

Crimson Wizard

#1
I'm sorry, I have trouble understanding these explanations in the video format. I need to know what do you have in script.

- Which variables do you have
- What script is run when you use one object, what script is run when you use another object.
- anything else related to the situation.

Something that I may note right away though: whenever I hear "I have 2 audio channels, one is called X and another is called Y", I immediately suspect that this is a wrong understanding of how audiochannels work. Because having a AudioChannel* variable in your script does not create a audiochannel, it is a reference to a audio channel which may or not point to an existing channel allocated by the engine.
This is explained in detail here: https://adventuregamestudio.github.io/ags-manual/AudioInScript.html

Grundislav

Ok, the variables are:
bool UpstairsRecord
bool DownstairsRecord
AudioChannel Phonograph
AudioChannel Phonograph2

My goal is to have the game check if a clip of audio type Record is playing on these channels, of which I have assigned a max of 2.

Under repeatedly_execute_always, my code is:
Code: ags
if (Phonograph != null && Phonograph.IsPlaying)
      {
        UpstairsRecord = true;
      }
      else
      {
        UpstairsRecord = false;
      }

      if (Phonograph2 != null && Phonograph2.IsPlaying)
      {
        DownstairsRecord = true;
      }
      else
      {
        DownstairsRecord = false;
      }

The idea is to play two different records simultaneously in two different rooms, and have them change in between.

Everything works fine, except when turning off one of the records using Phonograph.Stop or Phonograph2.Stop. After doing that, when playing a clip again on either audio channel, the game sets both of the above booleans to true.  So basically the problem is that UpstairsRecord and DownstairsRecord are both being set to true despite only Phonograph or Phonograph2 having a clip playing on them.

Crimson Wizard

#3
How do you assign Phonograph and Phonograph2 variables?

EDIT:
Also, you say in the video that the game crashes when you try to play again, but I do not see a crash demonstration in the video itself. Could you tell if there's a error message or anything when it crashes?

Grundislav

#4
Quote from: Crimson Wizard on Yesterday at 20:59:13How do you assign Phonograph and Phonograph2 variables?

I set them as global variables.

Sorry, "have them change in between" means allow them to continue playing in real time even when you leave the room. So if the record upstairs is playing and you leave the room, the audio channel's volume is set to 0. When returning upstairs, it's set back to its previous volume. If the record downstairs is also playing, the same thing applies.

The crash message in the video is just saying that a blocking function was called in rep_ex_always. This happens because I have it checking for UpstairsRecord being set to true and displaying a message when it is. The bug is that UpstairsRecord is being set to true even though Phonograph.IsPlaying is supposed to be set to false.

Crimson Wizard

Quote from: Grundislav on Yesterday at 21:06:03
Quote from: Crimson Wizard on Yesterday at 20:59:13How do you assign Phonograph and Phonograph2 variables?

I set them as global variables.

I mean, could you post a code of how do you assign them in script?

Grundislav

Code: ags
if (DownstairsRecord == true)
    {
      player.SayEx("I swapped out the currently playing record for the one I was carrying.");
      Phonograph2.Stop();
    }
    else
    {
      Game.StopAudio(eAudioTypeMusic);
    }
    if (Record == "Palesteena")
    {
      Phonograph2 = aPalesteena.Play();
      Record = RecordPlaying;
      RecordPlaying = "Palesteena";
    }

Crimson Wizard

I don't know what to say at this point.
AudioChannel.Stop just stops the current playback. If testing in a simple game it works well, and IsPlaying reports correct state. That's why I suspect a logical mistake somewhere in script, but I don't see the whole related script, so cannot tell.

In regards to the blocking action played in rep-exec-always, there are other ways to print messages without blocking the game:
* Character.SayBackground
* System.Log (and use Log Panel in the editor to see the game logs, if you are using AGS 3.6.1 or later)

Grundislav

I also suspected some logical error, but I can't find it. With regards to the above code, the line that causes the crash is Phonograph2 = aPalesteena.Play.

It makes no sense to me. If Phonograph is stopped, there's no reason why that line should make the game think a clip is playing on it. I can send you a build, as it's only 4 rooms, if you want to see all the code for yourself.

Crimson Wizard

Quote from: Grundislav on Yesterday at 21:40:03With regards to the above code, the line that causes the crash is Phonograph2 = aPalesteena.Play.

I am frankly confused, because earlier you said that the crash was caused by a blocking function called in rep_ex_always. Are these two separate crashes?

Quote from: Grundislav on Yesterday at 21:40:03It makes no sense to me. If Phonograph is stopped, there's no reason why that line should make the game think a clip is playing on it. I can send you a build, as it's only 4 rooms, if you want to see all the code for yourself.

Alright.

Grundislav

#10
Quote from: Crimson Wizard on Yesterday at 21:42:44
Quote from: Grundislav on Yesterday at 21:40:03With regards to the above code, the line that causes the crash is Phonograph2 = aPalesteena.Play.

I am frankly confused, because earlier you said that the crash was caused by a blocking function called in rep_ex_always.

Right. As I mentioned I have rep_ex_always in my room script that checks if UpstairsRecord == true. If it is, the game Displays a message and since it's a blocking function, it crashes the game. This is just my stupid way of testing whether something is executing in the script: if it crashes, I know it does.

The .Play line I mentioned causes the crash because when it gets to that point in the script, UpstairsRecord gets set to true.

UPDATE: It seems the solution was to set the AudioChannels back to null once they finished playing in my room's rep_ex_always scripts.


SMF spam blocked by CleanTalk