Overflow Exception when getting SoundInstance position
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.8k
- Forks
- 1.2k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 49
Description
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:
- You can create a new project out of the SimpleAudio template.
- Create a new SyncScript (or AsyncScript, adjusted accordingly).
- 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();
}
- 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();
}
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SimpleAudio template and reproduce the looping case using SoundInstance.Position during Update(). Trace the SoundInstance.Position implementation and the loop transition, then verify that checking the position during looping no longer throws a TimeSpan overflow exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100