Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Fatal crash + crippled feature in Unity Pro 4.3.4 (vs Unity Free)

Discussion in 'Editor & General Support' started by Peeling, Jun 3, 2014.

  1. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    399
    In addition to developing my own games, I also do some contract work. Today my employer gave me a license key for Unity Pro so that I could work on their title. I plugged it in, did my thing for the day, and then this evening loaded up my own app.

    Unity promptly tried to allocate 4 gig of memory and exploded.

    Two increasingly frantic hours later I tracked down the problem:

    Sprite.Create with a rectangle that lies outside the bounds of the texture causes Unity Pro to die.

    Now, you may not think that's a big deal. However, my app encodes additional per-sprite information into the UVs by adding on multiples of the size of the texture. The shader then decodes this additional information and uses it when rendering.

    Example: Suppose I want to draw a rotatable sprite with a bumpmap, AND pass in a per-sprite colour. To 'light' the bump map properly as the sprite rotates, I need to somehow pass in the local light vector for that sprite. So the total per-sprite info required is:

    Texture U,V
    Colour R,G,B,A
    Light Direction X,Y

    Colour values are clamped at 0-1, so they're no help. But I can pack extra information into the Texture UV by adding on multiples of the texture size.

    In practice the rotation (and thus light direction) changes far more often than the colour, so I pack the data as follows:

    Texture U + R*lots, V+G*lots
    Colour LX,LY,B,A

    and just tweak the red and green colour channels as I rotate the sprite.

    In Unity Free (4.3.4 and 4.5 - although 4.5 has 2D physics issues that forced me to roll back), this works perfectly. The sprite system accepts the values and passes them through to the shader.

    In Unity Pro, however, there seems to be some extra sanity checking. After some experimentation I found that if the right/top edge of the sprite rectangle hits the edge of the texture, the sprite starts changing shape, clamping those UVS. If the bottom/left corner approaches and passes the edge of the texture - bang. Crash to desktop.

    This might not be so much of an issue if Unity supported additional texture coordinate sets for sprites, so that more per-sprite data could be sent to the shaders. But as it stands, the ability to create arbitrary sprite UVs is *critical* for the graphical style of my application (which is already on the Play store awaiting an update). I'm dead in the water without it.

    If anyone has any suggestions for a workaround, or knows if this behaviour can somehow be disabled in Unity Pro, I'd be extremely grateful.

    Thanks,
    Andy Clitheroe.
     
  2. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    399
    Follow-up:

    Ok, I'm not dead in the water. I can scale down all texture coordinates by 256, then scale them back up in the shader before separating out U/R and V/G. So there is an out - it's just a really fugly one. And Unity shouldn't be screwing around with my sprites anyway - if I want the UVs there, that's where I want them! :)
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Have you thought of packing extra information into tangents? In any case please report this as a bug to Unity as it is a bug for it to crash on pro and not on free - just one that's slipped through.
     
  4. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    399
    Do sprites have tangents? I didn't know that...