Mono threads crashing debugger?

Hi. I’m writing some editor scripts which make POST requests to an HTTP server. Because of the latency of these requests, I do them all in threaded functions. The threads don’t persist, but fire off once for each HTTP request, set some global variable, and die off.

I am able to launch Unity as a debug session with these scripts in the project, but as soon as I open one of the windows (and a thread is started), Unity grinds to a halt and later crashes. I imagine this has something to do with the threads, since this is the first time I’ve noticed this particular behavior, but I could be wrong. I’ll also submit a bug, but I was wondering if perhaps anybody here has tried this, or had debugger problems with editor windows.

http request means?
If its WWW then its not allowed to use them in threads as with any unity engine class (and also not needed as they are async and the loading of the response is threaded)
if you use the webrequesters, keep in mind that they only work for standalone at all, no other platform supports them.

I’m finding the Unity crashes constantly when trying to use the debugger on the Mac, threads or no.

I’m not using WWW since it’s an Editor script. I usually call WWW from a coroutine (so that I don’t have to block the main thread, or clutter my Update function with a bunch of if(wwwInstance.isDone) blocks.

Either way, there’s no issue about working in any build targets, since this is for editor functionality. If you must know, it’s part of the AssetCloud plug-in that you and I were discussing in the Gossip forum :slight_smile:

With 3.2 / 3.3 it shouldn’t be a problem anymore as the debugger no longer attaches to the editor but the game process so editor scripts shouldn’t impact it at all anymore.

The only thing required for the threads is that they don’t touch anything that extends from a UnityEngine / UnityEditor class.

Your threads can calculate all the stuff they want to do and fetch what they want, but the data they set must be on System.Object based classes that are threadsafe, the UnityEngine / UnityEditor classes are not thread safe.

Errors are not logged when they occur in background threads (aka: not the main-thread). It could be you just have some exception in your threaded code that the game is hanging on but you never see the result. It’s a pretty annoying “feature” if you ask me.

I was actually talking about specifically trying to debug the editor windows. Everything goes fine until I put a breakpoint inside a threaded function.

Well, I’m not sure how I would determine this. All of the code executes. Sometimes when I was hitting an exception, the thread would just die in the background (without any kind of notification) but everything still crashes even when the code is exception-free… as far as I can tell.

Well the problem is that you can’t always tell if you hit an exception because Unity wont log it… I have never experienced the “everything crashing” when working with threads although I never started them from editor-windows. It’s quite possible the crash is caused by a multithreading problem unrelated to Unity as well… still I cant imagine a good reason why this would crash Unity itself unless you tried to access a locked property from Unity’s own thread.