andyburke / UnityHTTP

A TcpClient-based HTTP library for Unity.
GNU General Public License v2.0
593 stars 147 forks source link

Error when running in a thread #31

Closed Godefroy closed 9 years ago

Godefroy commented 9 years ago

Hi,

When I call a UnityHTTP method from a thread, I get this error:

get_unityVersion can only be called from the main thread.

To fix this and thus allow to use UnityHTTP in a thread, you can remove Application.unityVersion by replacing this line:

SetHeader( "User-Agent", "UnityWeb/1.0 (Unity " + Application.unityVersion + "; " + SystemInfo.operatingSystem + ")" );

by this line:

SetHeader( "User-Agent", "UnityWeb/1.0 (Unity; " + SystemInfo.operatingSystem + ")" );
ddaws commented 9 years ago

It would be nice to track the Unity version though this works for now. A solution to track the unity version would be to dispatch the call to Application.unityVersion to the main thread, though I don't have the time to dig into this now.

@Godefroy good find. If you have the time could you please make the changes and submit a PR?

Godefroy commented 9 years ago

Done :-) https://github.com/andyburke/UnityHTTP/pull/32

ddaws commented 9 years ago

Nice! Thanks :+1: