Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow Exception when getting SoundInstance position #2275

Open
FloccinaucinihilifilipicatesLongNames opened this issue May 25, 2024 · 3 comments
Labels
area-Audio bug Something isn't working

Comments

@FloccinaucinihilifilipicatesLongNames

Release Type: Official Release

Version: Latest

Describe the bug
I was testing a track by playing it on two SoundInstances for seamless playback looping but for some strange reason, I noticed it gives me an overflow exception with the message "TimeSpan overflowed because the duration is too long." when getting the position of any of the sound instances during the looping process.

To Reproduce
Steps to reproduce the behavior:

  1. You can create a new project out of the SimpleAudio template.
  2. Create a new SyncScript (or AsyncScript, adjusted accordingly).
  3. Add a SoundInstance and play it on Start():
public Sound Sound { get; set; }
private SoundInstance SoundInstance1;

public override void Start()
{
    // Initialization of the script.
    SoundInstance1 = Sound.CreateInstance();
    SoundInstance1.IsLooping = false;

    SoundInstance1.Play();
}
  1. During Update(), add a condition to play the track if the position is zero (or really, any calculation that needs the current position of the sound instance).
public override void Update()
{
    if (SoundInstance1.Position.Equals(TimeSpan.Zero)) SoundInstance1.Play();
}
  1. Wait for the track to loop back.
    In some cases, it loops back just fine, but other times during looping, it throws an overflow exception. Not entirely sure if this is only on my end but I've had it happen somewhat consistently so I figured I'd raise this issue.

Expected behavior
To loop back the track without throwing an exception every time.

Workaround
Granted, I was able to get a workaround going by getting the audio position through a method/local function returning a TimeSpan using a try-catch block but still, pretty odd occurrence.

@FloccinaucinihilifilipicatesLongNames FloccinaucinihilifilipicatesLongNames added the bug Something isn't working label May 25, 2024
@MechWarrior99
Copy link
Contributor

I was unable to reproduce this issue using either of the sounds from the audio template. I let loop a number of times to be sure, but worked fine for me on the latest version.

@FloccinaucinihilifilipicatesLongNames
Copy link
Author

FloccinaucinihilifilipicatesLongNames commented Sep 1, 2024

I was unable to reproduce this issue using either of the sounds from the audio template. I let loop a number of times to be sure, but worked fine for me on the latest version.

Interesting.
So I just tried it again in a new project and it worked nicely without any crashes whatsoever but then I reopened the old project that I originally used to test the problem with and it does keep happening.
I looked at both projects and it seems that the determining factor was that the sound file being played has the flag "Stream From Disk" enabled in Game Studio for the old one but the newer one has it disabled, same file and all. (If it helps any, the track being loaded is on an SSD)

Can you confirm if you get the exception with the Start() and Update() posted on the OP with the sound in Game Studio having the "Stream From Disk" flag enabled? It happened to me even with the sound effect from the template.

@MechWarrior99
Copy link
Contributor

Just tried it and I can confrim that when using the latest build, and Stream From Disk is enabled, it will give the exception. Interestingly though, when GameStudio is launched from the source code, it does not produce the error (tried in both debug mode and not).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Audio bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants