nixon-voxell / UnityTTS

Text to Speech in Unity.
Apache License 2.0
119 stars 23 forks source link

Unity Editor Crashes on textToSpeech.Dispose() and Stopping Game #2

Closed DrDungeonMaster closed 2 years ago

DrDungeonMaster commented 2 years ago

I've just started trying out UnityTTS and it seems to work great, except that when I click the 'play' button to stop running my project, it crashes to Desktop. I thought maybe this was happening because I wrote my own version of TTSDemo that didn't contain textToSpeech.Dispose() on disable, but turns out adding that and then disabling the TTSDemo-equivalent just crashes the game right then.

The code I was testing is extremely simple. This script is added onto the TTS object from the demo scene, which I turned into a prefab. It replaces TTSDemo. Basically, it just gives me a field where I can type messages, and when I press the selected button on a Steam VR controller (since it's a VR project I'm working on), it says whatever was typed in the box. No problem there, it's just afterwards things get nasty.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
using Voxell.Speech.TTS;

public class TTSTester : MonoBehaviour
{
    public SteamVR_Action_Boolean buttonPressed;
    public float cooldown = 3f;
    public TextToSpeech tts;
    public string speechTextString;
    private float timeSince = 0f;
    // Start is called before the first frame update
    void Start()
    {
        tts = transform.GetComponent<TextToSpeech>();
    }

    // Update is called once per frame
    void Update()
    {
        if (buttonPressed.lastActive && timeSince >= cooldown)
        {
            tts.Speak(speechTextString);
            timeSince = 0f;
        }
        timeSince += Time.deltaTime;
    }

    void OnDisable() => tts.Dispose();
}

In the Unity editor error logs, the stack trace at crash shows that something went wrong with TfLite.

========== OUTPUTTING STACK TRACE ==================

0x00007FF8CD298DA8 (libtensorflowlite_c) TfLiteVersion
0x00007FF8CD23128A (libtensorflowlite_c) TfLiteVersion
0x00007FF8CD231399 (libtensorflowlite_c) TfLiteVersion
0x00007FF8CD22DF3F (libtensorflowlite_c) TfLiteVersion
0x00007FF97DF61BB2 (ucrtbase) configthreadlocale
0x00007FF97F3A7034 (KERNEL32) BaseThreadInitThunk
0x00007FF980502651 (ntdll) RtlUserThreadStart

========== END OF STACKTRACE ===========

Looking into the crashdump, the only piece of useful information I can see is this: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.

I've never seen any kind of error like this in Unity before and have no idea how to change TfLite's memory access abilities. Any help or advice would be appreciated.

nixon-voxell commented 2 years ago

thank you for the bug report! super useful and detailed report you had there! I had also encountered reports similar to this error, will try to look into it!

DrDungeonMaster commented 2 years ago

Has there been any progress on this issue? I don't know how prevalent it is, but it makes the software entirely unusable.

nixon-voxell commented 2 years ago

hey, unfortunately I did not have the time to look into this issue yet, so sorry about that.. also, may I know if you are using the develop branch?

DrDungeonMaster commented 2 years ago

I am currently using the master branch -- should I switch to the develop branch?

Also, I am using Unity editor version 2021.3.1f1 and TensorflowLite 2.8.0.

nixon-voxell commented 2 years ago

Alright. Yeah definitely use the develop branch first as it will have the latest works I did.

nixon-voxell commented 2 years ago

Ah I just checked, there's no difference between dev and master.

nixon-voxell commented 2 years ago

hey I think this was fixed on the latest push, sorry forgot to mention it here.