Search Unity

Possible cross compiler crash with C# Plugin

Discussion in 'iOS and tvOS' started by dnf, Oct 23, 2008.

  1. dnf

    dnf

    Joined:
    Oct 6, 2008
    Posts:
    3
    Hi. First, fantastic job on the iPhone release... I took a vacation day just to play with it and it's even better than I hoped!

    However, I've run into a problem and I'm not sure if it's me or the cross compiler. I was trying to convert some of the procedural deformations from the Unity Procedural examples and ran into a hard crash with the cross compiler.

    On my system at least (Mac Mini, 1.83Ghz, Core 2 Duo, 1GB RAM) I can reproduce this crash 100% of the time. This is the message I get when building (after the standard Mac OS X "The application mono-iphone-xcompiler quit unexpectedly" dialog):

    Exception: Failed AOT cross compiling c757252fcfd8243c1a4e08c66c4b803c.dll
    UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.String iPhoneBundleIdentifier, Int32 iPhoneStrippingLevel, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options) (at /Users/joe/iphone-clean/Editor/Mono/PostprocessBuildPlayer.cs:567)

    To duplicate this problem, create a new, blank Unity iPhone project. Then:

    #1) Create a folder called "Plugins" in the Project view.
    #2) Create a new C Sharp Script in the Plugins folder (rename it to Crashy). Replace the sample class template with this:

    public class Crashy {

    float[,] g2 = new float[2,2];

    public Crashy() {
    g2[0,0] = 0.0f;
    }
    }

    #3) Save your scene.
    #4) Set up your iPhone Bundle Identifier in the Player Settings.

    Then build. On my system at least, I get a crash and a hung process that I have to kill from the Activity Monitor (or command line, it's called mono-iphone-xcom).

    The problem appears to be the assignment statement in the constructor. If I comment it out it builds just fine.

    Any suggestions? Is this an actual bug or am I doing something wrong?
     
  2. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Did you submit a bug on this? If so, did you ever get a response? I'm starting to have mystery crashes here too. I say "mystery" because Unity crashes completely and I can't find any particular portion of my code that is doing it. I'm starting to think it may be mono.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    iPhone Mono is .NET 1.1, unlike the regular iPhone Mono which is .NET 2.0 or even higher

    This might be the reason that this default assignment thingy does not work.
    There are no generics and other "flexible" things on the iPhone end and this default initiation behavior might just be another thing. Don't know by which .NET version automatic initialization support
     
  4. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Well, I solved my problem now and it didn't turn out to be mono related as far as I can tell (probably physics related). But I was thinking, I don't know much about the internal workings of C# (I'm a C++ guy and variable initialization can't be done in the declaration), but is it possible that the initialization ( = new float[2,2]) doesn't take place until after the class constructor is called? In which case, you'd be trying to assign a value to an array that has not yet been created. Instead, perhaps try removing the "= new float[2,2]" and instead put it in the constructor, and then try assigning a value to it.

    It may be way off base, but just a thought.
     
  5. dnf

    dnf

    Joined:
    Oct 6, 2008
    Posts:
    3
    I did submit a bug report and sample project but I was also able to work around it by using ragged arrays. Ragged arrays can have a small speed penalty (with certain array access patterns) compared to actual multi-dimensional arrays so I hope this is an issue that can be solved at some point anyway.

    The default Unity Lightning demo (from the Procedural demos) ran as slow as molasses on the iPhone. This turned out to be from the Perlin noise generator that was used since the original Perlin noise generator has a lot of floating point operations.

    I also tried using Ken Perlin's "improved Perlin noise" ( http://mrl.nyu.edu/~perlin/noise/ ) as well as his replacement for Perlin noise (Simplex noise: http://mrl.nyu.edu/~perlin/homepage2006/simplex_noise/index.html , http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf ) and got quite a bit of a speed boost but I was still only able to use two lighting balls instead of 5 like in the demo.

    It looked pretty good in the end though!
     
  6. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    This will be fixed with next Unity iPhone release.