Random sound playing when SetView loop is empty

Started by Laura Hunt, Sun 20/11/2022 11:04:10

Previous topic - Next topic

Laura Hunt

This is kind of a weird one and it might be difficult to explain, but I'll try my best. Using 3.6.0 RC 2.

In a test room for my game, I'm doing the following:

Code: ags
oExampleObject.SetView(FIRSTVIEW);
oExampleObject.Animate(2, 6, eOnce, eBlock);
oExampleObject.SetView(SECONDVIEW);
oExampleObject.Animate(2, 6, eOnce, eBlock);
oExampleObject.SetView(THIRDVIEW);
oExampleObject.Animate(2, 6, eOnce, eBlock);

I know that when you call SetView without the optional loop and frame parameters these default to 0, so that what I'm doing here is equivalent to oExampleObject.SetView(FIRSTVIEW, 0, 0).

However, I made a tiny mistake here, because loop 0 for FIRSTVIEW, SECONDVIEW and THIRDVIEW is empty.

I would expect the game to maybe crash or throw a warning in this case, but what it's doing instead is playing a frame-linked audio that belongs to a completely different view from any of these three every time the SetView command is triggered.

Furthermore, I have not called SetView on any object or GUI button before this.

Obviously what I need to do is set the correct loop in the SetView command: oExampleObject.SetView(FIRSTVIEW, 2). Still, this is very confusing, because I have no idea why AGS is choosing to trigger that specific view and frame when it finds an empty loop.

Anybody have any idea what might be going on here?

Khris

I did a quick test and can easily reproduce this. If the first loop of the view is empty, AGS falls back on sprite #0, then plays sound #0.
The former makes sense, the latter is clearly a bug.

Laura Hunt

#2
Quote from: Khris on Sun 20/11/2022 14:10:06I did a quick test and can easily reproduce this. If the first loop of the view is empty, AGS falls back on sprite #0, then plays sound #0.

Of course! It didn't occur to me that the sound that plays is precisely the one with ID 0. Good catch!

I can't test this right now, but what happens if you try to set another loop that doesn't exist and isn't loop 0? For example, in my case, FIRSTVIEW only has loop 2, so what happens if you try to SetView (FIRSTVIEW, 1)?

EDIT: I was finally able to test it myself and the same thing happens if you assign any existing but empty loop.

If, on the other hand, you assign a non-existing loop (for example (FIRSTVIEW, 3) in my case), the engine will crash with an "invalid loop number" error as expected.

Crimson Wizard

The reason for this: AGS creates 1 dummy frame for each empty loop, but the "linked sound" parameter of this dummy frame has wrong value - #0 instead of "no sound", so it thinks that it should play sound #0.


SMF spam blocked by CleanTalk