readyplayerme / rpm-unity-sdk-core

This Module contains all the core functionality required for using Ready Player Me avatars in Unity, including avatar loading and creation
MIT License
89 stars 30 forks source link

VoiceHandler memory access out of bounds on WebGL #320

Open baaskoen opened 2 days ago

baaskoen commented 2 days ago

Describe the bug When the assigned audio clip in the VoiceHandler script is played in the browser, the app will crash as soon as the audio stops playing. Happens on all browsers. The audio clip will play just fine, the exception is thrown when it ends.

Files

I'm using an empty project with no modifications, only an imported character and a tiny mp3 file.

To Reproduce

  1. Import a RPM character
  2. Add the VoiceHandler component
  3. Set AudioProvider to "AudioClip" on that component
  4. Assign a random audio clip (I had the same error on different audio files)
  5. Build to WebGL and play the audio (via canvas button for example, or play on awake)

Expected behavior There should be no memory exception. When playing the audio manually without the VoiceHandler on a differen unity node produces no error.

Screenshots

Screenshot 2024-10-02 at 09 56 14

Screenshot 2024-10-02 at 09 56 31

Desktop (please complete the following information):

additionally (if significant for the bug):

baaskoen commented 2 days ago

I locally modified the VoiceHandler @ GetAmplitude method so that it compares the timeSamples:

private float GetAmplitude()
{
    if (CanGetAmplitude)
    {
        var amplitude = 0f;

        if (AudioSource.timeSamples + AUDIO_SAMPLE_LENGTH > AudioSource.clip.samples)
        {
            Debug.LogError("Requested samples exceed available samples in the clip.");
            return 0f;
        }

        AudioSource.clip.GetData(audioSample, AudioSource.timeSamples);

        foreach (var sample in audioSample)
        {
            amplitude += Mathf.Abs(sample);
        }

        return Mathf.Clamp01(amplitude / audioSample.Length * AMPLITUDE_MULTIPLIER);
    }

    return 0;
}

This prevents the app from crashing, although it will still log the error multiple times.

rk132 commented 1 day ago

Thanks for reporting, we will look into it.