Skip to content

Mainthread, null thread #144

Closed
Closed
@unitycoder

Description

@unitycoder

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);
                    }
                }
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions