iPhone + Unity = No multithreading

I have been holding off until now to really post this problem, I am not sure and don’t even think it is a bug, the programs work in the Editor, they work when compiled for the Mac and they work when compiled for Windows, but when i compile them for the iPhone (although in the editor they work), when they load up, the moment it gets to the threaded portion of the code, the program bombs.

I have also found that C# translation doesn’t happen very well and it is best to just script everything in javascript with strict code declarations. So, is it my imagination, or just me, that it is best to code from scratch everything into javascript and ditch my C# code, get rid of System.Threading all together in the applications? I didn’t want to bug anyone about this, but it has been one major hangup for me these past few weeks on all of my programs that I have written for the iPhone.

I would say- file bug reports, if you have code that runs in the Editor but not on the phone. The AOT compiler should warn about stuff that is not supported on the device, or if you have more .net assemblies than the compiler can deal with.

I for instance I cannot use XML serialization because I have an indie license of Unity iphone. But the compiler tells me so.

That said, multithreading isn’t mentioned in the Unity manual at all? The recommended technique in the manual is Coroutines Yield.

Couroutines and Yield work with javascript code but do not work with C# code, the engine has always paused on me while it waited on exeuction of sound trigger or what ever, so say I fired at a target, while the sound played, the program hung, once the sound was through playing it continued, only way around this in C# was to write a sound tread device that placed the sound on its own thread. This has always been the case, been over this in heated discussions in the past and sent in entire code blocks showing this problem. This is where I think the programs are bombing in the iPhone application, the moment the sound threads begin for playing, it hangs and bombs out on the iPhone. Basically when my bullet hits an enemy, using normal Unity calls withouth threading, the engine pauses 100% of the time, always has, after the explosion sound, from that unit, then the game continues. Others have always argued it was something that I was doing wrong in my C# code, but using yield on a javascript block of code doesn’t have the pause, but using wait on c# code, never works right. I am a c# coder, not much of a javascript fan, but this might be where my problem resides, if Threading is just not supported on the iPhone, cool, I’ll rewrite everything. Just not a fond idea at the moment.

Can anyone at UT state if System.Threading is supported on the iPhone or not?

Thanks

Threading isn’t currently supported with Unity iPhone but it will be in the next release.

Mantas Puida mentioned it at the end of this post.
http://forum.unity3d.com/viewtopic.php?t=17363

Thanks, this explains everything I have been having problems with these past few weeks. I am glad I am not the only one with the issue and that it is been worked on. This delayed my push to Apple since I can’t have that happening in my application and pass Apples QA team. They will kick it back at me.

I haven’t worked on the save game feature yet on my programs, so if we are not allowed to use XML Serialization on the Basic version how do we save our games?

NO where on this link does it state we are no able to use XMLSerialization (whih is how I planned on doing my game saves/loads) and it is critical to this effect, if they are denying basic owners this feature and it wasn’t stated up front, they need to enable it for basic users becuase it is simply not advertised as not allowed. What is not allowed is strictly stated for the difference between iPhone Basic and iPhone Pro.

I guess I need to open a complaint ticket on this issue then, since it is a “hidden” lock out for version difference.

In addition to be exteremly clear on this fact and to make sure they don’t just ‘correct’ the license page (you buy items based on advertised license limitations), I have placed with a date/time stamp, the license differences in a PDF. This will make sure someone doesn’t hop onto the page and make a modification and say it was in the advertisement from the begining.

Attached is the ONLY limitations between the Basic and Pro version in a time/date stamped PDF, so what you have now should ONLY have these limitations between basic and advanced.

125568–4701–$unity_license_comparison_192.pdf (57.9 KB)

Yield of course works in C#; the syntax is different from Javascript, as explained in the docs (must explicitly use “StartCoroutine” and IEnumerator for the coroutine). Save your game using PlayerPrefs.

–Eric

Thanks Eric, but I have tried the other way for C# and it doesn’t work for me, never has. The code doesn’t error, just doesn’t work. I know what the docs say about it, but what the docs say doesn’t work for me, so I was forced to find another solution.

XML is nowhere explicitely mentioned to be a feature of Unity iPhone at all.

Additionally its not disallowed on iphone basic.
You just pass the maximum size of libraries you can have in your app and it will either not compile the app in XCode or crash on the phone.

Thats the reason why iPhone Advanced has a chance to work, as stripping can cut other stuff to open up the required room for XML.

Additionally, Unity iPhone is .NET 1.1, so part of System.XML (several classes are missing) you might be used to does not exist at all.

But I understand that it might frustrate you to run up that unexpected wall.
There is a thread on iPhone Basic XML and I think there is also a resources offered to make XML usable to iPhone Basic licensees when I remember right.

@zumwalt: any specific code that shows that behavior?
Because I’ve not had problems so far, but perhaps they are hidding themself behind something and don’t show up obviously enough as there isn’t too much that runs in parallel right now.
I’m strictly C# so I guess it would be a pretty ugly disaster if this really would be the case.

Hello,
please submit bug report with sample project attached to it.

You have a few submitted projects in your bug system from me with this issue back in 2007, I submitted some with just how to produce this. All of my current projects no longer use this method from the manual, instead they all use threading model. If you want me to create another project to demonstrate this problem, I can, but I will probably post it here also in the threads so it doesn’t get accidently “lost” in the bug system. I have tons of problems in the bug system all closed an unanswered, so I don’t think it is a viable solution to submit anything to get looked at.

EDIT:
Per your request, I have submitted a bug report with a project attached, very clean and crisp, no standard or pro assets in it, simply 3 cubes, 2 scripts 1 image and 1 sound byte. The cube in the center hits the other 2 cubes and when it does, it pauses until the sound is finished paying, then it continues until it hits the next cube, sort of a generic pong without the paddles moving.

Hello zumwalt,
please PM me bug number and I will take a look at it.

Just grab the project I just submitted. It at least is compiled in 2.1 as of today and should demonstrate the problem cleanly for you.

EDIT:
That exact same simple project when deployed on the iPhone does absolutely nothing. The cubes don’t even show up. And this is extremely basic code and objects along with image on cubes. Part of the same problem I have seen now for a few weeks, take what you have been given and deploy it to the iPhone to see what I am talking about. iPhone Basic simply can’t translate C# very well IMO.

And here is the output debug log from the iPhone from XCode:

[Session started at 2009-02-25 19:55:58 -0600.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-963) (Tue Dec 9 06:23:51 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “–host=i386-apple-darwin --target=arm-apple-darwin”.tty /dev/ttys000
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-3709-21
Switching to remote protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
sharedlibrary apply-load-rules all
run
Running…
[Switching to thread 10755]
[Switching to thread 10755]
(gdb) continue
Unity runtime class registered 7251220
Unity runtime class registered 7296268
Unity runtime class registered 7394732
Unity runtime class registered 7409312
Unity runtime class registered 7425736
Unity runtime class registered 7427732
Unity runtime class registered 7433920
Unity runtime class registered 7483260
Unity runtime class registered 7483248
Unity runtime class registered 7483272
Unity runtime class registered 7483284
Unity runtime class registered 7539524
Unity runtime class registered 7483304
Unity runtime class registered 8160408
Unity runtime class registered 8227988
Unity runtime class registered 8357664
Unity runtime class registered 8385696
Unity runtime class registered 8760256
Unity runtime class registered 8903096
Unity runtime class registered 7573140
Unity runtime class registered 7580676
Unity runtime class registered 7527240
Unity runtime class registered 7566548
Unity runtime class registered 7594540
Unity runtime class registered 7652596
Unity runtime class registered 7684020
Unity runtime class registered 7897164
Unity runtime class registered 8021712
Unity runtime class registered 8180740
Unity runtime class registered 8652996
Unity runtime class registered 8722820
Unity runtime class registered 8491608
Unity runtime class registered 8497412
Unity runtime class registered 8890480
Unity runtime class registered 9051820
Unity runtime class registered 9060728
Unity runtime class registered 7683836
Unity runtime class registered 8870472
Unity runtime class registered 7543104
Unity runtime class registered 7656680
Unity runtime class registered 7686460
Unity runtime class registered 7686448
Unity runtime class registered 7711752
Unity runtime class registered 7888380
Unity runtime class registered 7888576
Unity runtime class registered 7888544
Unity runtime class registered 7686388
Unity runtime class registered 8025480
Unity runtime class registered 8059936
Unity runtime class registered 8067508
Unity runtime class registered 8156908
Unity runtime class registered 8195000
Unity runtime class registered 8610220
Unity runtime class registered 8616624
Unity runtime class registered 8640784
Unity runtime class registered 8673500
Unity runtime class registered 8674136
Unity runtime class registered 8043460
Unity runtime class registered 8678356
Unity runtime class registered 8663544
Unity runtime class registered 8813460
Unity runtime class registered 8872068
Unity runtime class registered 8887724
Unity runtime class registered 7481552
Unity runtime class registered 8914780
Unity runtime class registered 8934224
Unity runtime class registered 8935868
Unity runtime class registered 8951944
Unity runtime class registered 8951956
Unity runtime class registered 8970560
Unity runtime class registered 7672488
Unity runtime class registered 8186236
Unity runtime class registered 8450684
Unity runtime class registered 7531340
Unity runtime class registered 7671964
Unity runtime class registered 8524212
Unity runtime class registered 8525024
Unity runtime class registered 7672488
Unity runtime class registered 8186236
Unity runtime class registered 8432856
Unity runtime class registered 8438908
Unity runtime class registered 8450684
Unity runtime class registered 7844892
Unity runtime class registered 7846104
Unity runtime class registered 7869812
Unity runtime class registered 7876792
2009-02-25 19:56:34.261 iPongX[63:20b] → registered unity classes
2009-02-25 19:56:34.337 iPongX[63:20b] → registered mono modules
→ applicationDidFinishLaunching()
Couldn’t load the script “BoundingVolumeArea” because its file name doesn’t match the class name.
Please make sure the file name of the script is the same as the class defined inside it.
(Filename: /Users/joe/iphone-clean/Projects/…/Runtime/Mono/MonoScript.cpp Line: 409)

Couldn’t load the script “ViewArea” because its file name doesn’t match the class name.
Please make sure the file name of the script is the same as the class defined inside it.
(Filename: /Users/joe/iphone-clean/Projects/…/Runtime/Mono/MonoScript.cpp Line: 409)

End Load File completely 329.877500

→ applicationDidBecomeActive()
NullReferenceException occured in:
No method at 0x76cc6c
[Switching to thread 11779]
[Switching to thread 11779]
(gdb)

NOTE:
/Users/joe/iphone-clean/Projects…

DOES NOT EXIST ON MY MACHINE, this seems to be hard coded into your iPhone SDK

EDIT:
Second bug report just sent in, the sound was disassociated by the player after saving the scene in 2.1 and quitting Unity, when loading back into the editor, no sounds were associated with sound sources, that is on the report and the project is attached, again, to the bug report.

Same project can be copied and loaded separately into iPhone basic to see results. These are continuing problems with Unity 2.1 and iPhone Basic 1.0.1

I can’t deploy ANY iPhone games until these issues are resolved and it is costing me tons of time. If I saw the MONO code and figured out why it was bombing on Line 409 or what ever, then I could trouble shoot your code and figure out why it is constantly breaking.

I get that error on line 409 too, but it doesn’t crash the program.

It looks like what is actually causing the problem is a null reference exception somewhere in your scripts. Maybe you are using an unsupported sound format?

I am using 100% supported sound files, they have the project and they can just put it on an iPhone there. If a program with 3 cubes, no prefabs, 1 texture, 1 sound file, 2 scripts, one that moves the middle block up and down and 1 that plays sound doesn’t work, there are serious issues. They have not responded yet with any information about why it doesn’t work on the iPhone nor why the sound pauses.

They would have known instantly, within 5 minutes of grabbing the project, and dropping it onto an iPhone to see that it has issues. I can’t see how or why this would have gotten through quality control before version 1.0 was out let alone 1.0.1.

My sound is a WAV file and it is very small in size.
I figured within 72 hours I would hear something back from them, so giving them a few days to test it on both the Mac and the iPhone.

Also, forgot to mention, I have converted the wav to m4a and did a re-import to see if that worked and still the same problem. I removed the sound component all together, still the same issue, loads splash screen, unity logo goes way and nothing but black screen. Console in XCode shows:

End Load File completely 312.403833

→ applicationDidBecomeActive()
NullReferenceException occured in:
No method at 0x76cc6c
[Switching to thread 11779]
[Switching to thread 11779]
(gdb)

This is telling me that it is still crashing before running, period.
2 weeks of this so far of these crashes, I have tried everything. As mentioned they have a TINY test project, and if they can’t blow up iPhone Basic with that, then this is hopeless.

I just sent in another full crash log from the iPhone itself, they should be able to easily read it on their end.

The real problem is that NullReferenceException, which unfortunately could be anything. Do you have any lights in your scene? And if so, do you have any particles or line renderers? There is a bug where if you have lights on particles/line renderers, then the engine will crash with a NullReferenceException.

Other than that, I’m not sure what it could be. How are you playing the sounds? You can’t have more than one compressed (mp3, m4a) sound playing at a time. Everything else has to be uncompressed sound (WAV, etc).

edit:
Also, you say you have problems with C# and coroutines/yield, but I have a shipping game using them, so they obviously work. The C# syntax takes some getting used to, especially considering that the docs don’t exactly say everything there is to know about them.

The project I gave them has 1 and only 1 sound file in it, it is in uncompressed WAV format, it has 1 image file, that is all the additional resources it has. I used built in cube and copied it 2 times to make a total of 3 cubes, I then applied the image to all 3 cubes. The outer 2 have the sound script I wrote attached to it and it just has 1 coroutine in it, this coroutine plays the sound which is played for ~< 1 second the middle cube has a movement script attached to it that just makes it move as a rigidbody up and down between the other two cubes at a constant velocity *-1 flipped to *1 when on trigger enter is called. Coroutines do not function properly in all circumstances.

If a coroutine performs work that is a lot of work, they tend to crash windows machines, found this out the hard way, putting the same code in my own thread and doing a thread.start, the same exact code has no problems runnin on Windows or Mac. Simply put, by now, with that project which has no standard assets or pro assets in it, totally stripped down to 3 cubes, 1 sound byte of an uncompressed WAV file and 2 simple script files, they could have and should have already tried it on iPhone Basic along with compiling in 2.1 on their end and running on an iMac.

Just for arguements sake, when I get a chance later tonight and get back to the home office where I have the project, I will post the 2 code CS files that are being used. I am waiting on them to respond to the tickets and tell me exactly what I have to do to get that simple project to run on the iPhone, once they do that, I will probably have my answer for the remaining projects. I suspect it is the difference between what iPhone Advanced can do for stripping unused items vs iPhone Basic. Granted I am not including anything other than unityengine and system.collections, but that might be to much to include, if it is, well, iPhone Basic doesn’t have either a good business model nor a functional development model.

Of all of my other iPhone Basic projects, none of them have a light source attached, other than the built in one that is in the project that is the global light source, the project I sent them has 1 point light in it as a test. The others have no additional lights. They all use uncompressed MONO WAV files, the one I sent them has an uncompressed WAV file, the others have all images at the power of 2, the one I sent them has an image I pulled from my picture library from easter of 2 bunnies in a chair holding candy jars and is a 640x480 imate. All of my other projects are thousands of lines of code, tons of prefabs and all work in Unity, none work on the iPhone without crashing it, including the simple one I sent them.

I’ve spent the last few weeks going over every module, every code block, every sound source, everything in all of those projects trying to find a common cause, just can’t. And since the project I made for them and sent in has absolutly none of the stuff the other projects have in them as far as complexity is converned, it should just “work” on the iPhone, whether it is basic or advanced, but it also crashes.

I am stuck between a rock and a hard place.

Maybe you should post some project or code here. You posted a PDF of the license web page. People might be scared off from helping if they think they will be a party to a lawsuit or something.

It sounds like you could have found a defect in the engine, however your coding style must be significantly different than the tons of other C# devs around here (on iPhone and with Unity in general).

Lots of games getting published on the iphone already and I don’t think they are all written in Javascript. I am using Javascript and don’t really know C#. So I am just making a suggestion. Good luck

If you have a sample project demonstrating the bug that you want to post here, I wouldn’t mind looking at it to try and pinpoint the problem. If there is a problem with the engine it helps us all to resolve the issue.