Skip to content

Commit 8335560

Browse files
SRV-1434 webgl voice handler outofbounds (#322)
<!-- Copy the TICKETID for this task from Jira and add it to the PR name in brackets --> <!-- PR name should look like: [TICKETID] My Pull Request --> <!-- Add link for the ticket here editing the TICKETID--> ## [SRV-1434](https://ready-player-me.atlassian.net/browse/SRV-1434) ## Description - This changes adds additional checks that would limit reaching memory access out of bounds on WebGL error. <!-- Fill the section below with Added, Updated and Removed information. --> <!-- If there is no item under one of the lists remove it's title. --> <!-- Testability --> ## How to Test - Create new project, import example scene - add VoiceHandler component - set build target to webGL and run the built application <!-- Update your progress with the task here --> ## Checklist - [ ] Tests written or updated for the changes. - [ ] Documentation is updated. - [ ] Changelog is updated. <!--- Remember to copy the Changes Section into the commit message when you close the PR --> [SRV-1434]: https://ready-player-me.atlassian.net/browse/SRV-1434?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents 70f3e7a + 4f5a3a9 commit 8335560

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Runtime/Core/Scripts/Animation/VoiceHandler.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class VoiceHandler : MonoBehaviour
4646
private bool CanGetAmplitude => AudioSource != null && AudioSource.clip != null && AudioSource.isPlaying;
4747

4848
private CancellationTokenSource ctxSource;
49-
49+
5050
private void Start()
5151
{
5252
CreateBlendshapeMeshMap();
@@ -165,10 +165,17 @@ public void PlayAudioClip(AudioClip audioClip)
165165

166166
private float GetAmplitude()
167167
{
168-
if (CanGetAmplitude)
168+
if (CanGetAmplitude && AudioSource.clip.loadState == AudioDataLoadState.Loaded)
169169
{
170-
var amplitude = 0f;
170+
var currentPosition = AudioSource.timeSamples;
171+
var remaining = AudioSource.clip.samples - currentPosition;
172+
if (remaining > 0 && remaining < AUDIO_SAMPLE_LENGTH)
173+
{
174+
return 0f;
175+
}
176+
171177
AudioSource.clip.GetData(audioSample, AudioSource.timeSamples);
178+
var amplitude = 0f;
172179

173180
foreach (var sample in audioSample)
174181
{
@@ -178,7 +185,7 @@ private float GetAmplitude()
178185
return Mathf.Clamp01(amplitude / audioSample.Length * AMPLITUDE_MULTIPLIER);
179186
}
180187

181-
return 0;
188+
return 0f;
182189
}
183190

184191
#region Blend Shape Movement

0 commit comments

Comments
 (0)