Search Unity

JIT errors-- and pragmas to help?

Discussion in 'iOS and tvOS' started by iceshaft07, Dec 7, 2010.

  1. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    Hey-- I'm getting JIT errors. I'm typically good at avoiding these, but every now and then I slip up. These are kind of hard to find because right now I am getting something about get_length(object,object[])

    and I have no idea where that might be.

    Would #pragma strict help (I don't always use it because there are a few cases where I have no idea what it whines about, but it doesn't seem to hurt the iPhone)? What other pragma's can I use?

    Thanks,

    -Rob
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You have to use #pragma strict on all scripts used for iOS publishing.

    --Eric
     
  3. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    Eric, I'm not sure if I do because I have released games without it.

    Did you mean something else, or am I just writing particularly clean code?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If the code you write is 100% compliant with code that works with #pragma strict, then no, technically it's not necessary. But why bother to leave it out? It doesn't help you to do that. If #pragma strict "whines" about something, you have to fix it. However, I think if you add #pragma downcast and #pragma implicit, that code will still compile on iOS. I think this was handled better in Unity iPhone prior to Unity 3, where all scripts essentially had #pragma strict applied automatically, so you didn't have to think about it.

    --Eric
     
    Last edited: Dec 7, 2010
  5. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    Eric, do you have somewhere I can find more information on pragma strict?

    I've asked on the forums a few times, and people have not ever responded to my requests. I've searched on google for answers on Action Script 3, since that is usually relevant, but not much comes up.

    I only said "whines" because I find that whenever strict modes find something wrong with my code, I have never found an answer. I've read books where the author will recommend using it , but once I run into a problem with no answers, I take it off. An example of this might be something like knowing how to use strict mode for an array, but once you use a two or three dimensional array, strict mode goes beserk.

    I'm very willing to use it strict for everything-- I perfer to have it on where possible. If you can supply me the information, I will read it. Asking a question on a forum about every strict mode error that goes wrong seems excessive. I take my career seriously, and if there is something you know that I do not, I will make sure to actively search out the information.
     
  6. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    992
    It's mostly likely a dynamic typing error, when you assign variables you need to tell unity what type it is usually with the "as" command or by declaring the variable type before hand.

    e.g.

    obj = GameObject.FindWithTag("SomeTag") as GameObject;
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    #pragma strict just removes the ability to do dynamic typing. e.g.,

    Code (csharp):
    1. var rb = GetComponent(Rigidbody);
    2. rb.useGravity = false;
    As you can see in the docs, and as the name of the command suggests, GetComponent returns a Component, so "rb" is cast as a Component. But .useGravity is not a member of Component, it's a member of Rigidbody. Dynamic typing figures out that you actually want a Rigidbody here, not Component. However, that's slow, and #pragma strict won't allow it. Fix that by casting to the appropriate type:

    Code (csharp):
    1. var rb = GetComponent(Rigidbody) as Rigidbody;
    2. // or use generics:
    3. var rb = GetComponent.<Rigidbody>();
    (Yes, you can use rigidbody.useGravity and avoid GetComponent anyway, but that's just a quick example of the concept.)

    --Eric
     
  8. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    I knew that-- I was looking for more advanced solutions to problems (such as the 'as' operator which is not used in the Unity Docs as far as I have seen). The as keyword solves a lot of issues, but searching for the word 'as' on google isn't very helpful. Its pretty self explanitory to make sure an int goes into an int, but the GetComponent ones were a bit harder.

    There are some casts that I just can't figure out how to do, and I don't intend on double posting the same question, so Eric, would you mind helping me out over here?:

    Code (csharp):
    1. http://forum.unity3d.com/threads/69915-Pragma-strict-errors
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    When you get such errors, always lookup in the script reference what return class type you get and what you would need.

    This works for all that is not array cast as mentioned on the thread. No way to get around it through casting, you will have to go the dirty way of writting a function that casts the whole content manually for you one by one.
    The only way to get around would be if you used a generic datastructure from System.Collections.Generic like List<>, LinkedList<>, ...