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

Mainthread, null thread #144

Open
unitycoder opened this issue Mar 13, 2024 · 0 comments
Open

Mainthread, null thread #144

unitycoder opened this issue Mar 13, 2024 · 0 comments
Labels

Comments

@unitycoder
Copy link
Owner

Someone reported issues with mainthread.cs
and suggested small fix (below this code)

Assets\PointCloudTools\PointCloudViewerDX11\Scripts\Common\MainThread.cs:

     IEnumerator Executer()
        {
            while (true)
            {
                yield return null;
                while (calls.Count > 0)
                {
                    calls[0].Execute(); // ← thread unsafe! GC may occur if it is added by another thread. 
                    lock (callsLock)
                    {
                        calls.RemoveAt(0);
                    }
                }

                while (functions.Count > 0)
                {
                       if(functions[0] != null){ 
                       functions[0](); // ← thread unsafe! GC may occur if it is added by another thread.
                    }
                    lock (functionsLock)
                    {
                        functions.RemoveAt(0);
                    }
                }
            }
        }

modified:

IEnumerator Executer()
        {
            while (true)
            {
                yield return null;
                while (calls.Count > 0)
                {
                    CallInfo call_work = null;
                    lock (callsLock) {
                        call_work = calls[0];
                    }

                    call_work.Execute();

                    lock (callsLock)
                    {
                        calls.RemoveAt(0);
                    }
                }

                while (functions.Count > 0)
                {
                    Func func_work = null;
                    lock (functionsLock)
                    {
                        func_work = functions[0];
                    }
            if( func_work != null){
                        func_work();
                    }
                    lock (functionsLock)
                    {
                        functions.RemoveAt(0);
                    }
                }
            }
        }
@unitycoder unitycoder added the bug label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant