Search Unity

Black screen when loading on iPad

Discussion in 'Editor & General Support' started by Rogetsss, Jul 12, 2012.

  1. Rogetsss

    Rogetsss

    Joined:
    Jul 11, 2012
    Posts:
    12
    Hi!

    Since I updated unity to 3.5.3 from 3.5.2, I now have a black screen on any iPad after the splash screen image and before the in-game for several seconds. During this black screen, there is the standard iOS loading animation (). When it's finished the game starts properly.

    It think it may be related to the bugfix in the latest release that fixes splash orientation problems. (Release note : "iOS: Fixed all the issues with splash orientation.")

    Has anybody got the same problem?

    Thx!
     
  2. iSO-FORM

    iSO-FORM

    Joined:
    Jul 15, 2012
    Posts:
    4
    Hi,

    I'm seeing the same thing since I upgraded to 3.5.3 but only when I start the app in portrait mode, when started in landscape mode it seems to work fine. I hope someone can find a workaround, I kind of like the loading animation and don't want to have to remove that.

    Russ
     
  3. Rogetsss

    Rogetsss

    Joined:
    Jul 11, 2012
    Posts:
    12
    Nice, I haven't tried in landscape. This is definitely related to these new orientation fixes made by unity in the last patch...

    We found a workaround, but I don't know all the consequences that it may imply. Maybe it will not suit you, but you may give it a try :) We compared the code generated in AppController.mm by 3.5.2 with code generated by 3.5.3 and found some differences. So we modified the code of 3.5.3 to fix the problem and when we build in unity to xcode project, we replace the generated AppController.mm by the one we modified.

    In our modified AppController.mm, we first put back the function CreateSplashView() that 3.5.2 originally generated :

    Code (csharp):
    1.  
    2. NSString* SplashViewImage( UIInterfaceOrientation orient )
    3. {
    4.     bool need2xSplash = false;
    5. #ifdef __IPHONE_4_0
    6.     if ( [[UIScreen mainScreen] respondsToSelector:@selector(scale)]  [UIScreen mainScreen].scale > 1.0 )
    7.         need2xSplash = true;
    8. #endif
    9.  
    10.     bool needOrientedSplash = false;
    11.     bool needPortraitSplash = true;
    12.  
    13.     if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
    14.     {
    15.         bool devicePortrait  = UIDeviceOrientationIsPortrait(orient);
    16.         bool deviceLandscape = UIDeviceOrientationIsLandscape(orient);
    17.  
    18.         NSArray* supportedOrientation = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
    19.         bool rotateToPortrait  =   [supportedOrientation containsObject: @"UIInterfaceOrientationPortrait"]
    20.                                 || [supportedOrientation containsObject: @"UIInterfaceOrientationPortraitUpsideDown"];
    21.         bool rotateToLandscape =   [supportedOrientation containsObject: @"UIInterfaceOrientationLandscapeLeft"]
    22.                                 || [supportedOrientation containsObject: @"UIInterfaceOrientationLandscapeRight"];
    23.  
    24.  
    25.         needOrientedSplash = true;
    26.         if (devicePortrait  rotateToPortrait)
    27.             needPortraitSplash = true;
    28.         else if (deviceLandscape  rotateToLandscape)
    29.             needPortraitSplash = false;
    30.         else if (rotateToPortrait)
    31.             needPortraitSplash = true;
    32.         else
    33.             needPortraitSplash = false;
    34.     }
    35.  
    36.     const char* portraitSuffix  = needOrientedSplash ? "-Portrait" : "";
    37.     const char* landscapeSuffix = needOrientedSplash ? "-Landscape" : "";
    38.  
    39.     const char* szSuffix        = need2xSplash ? "@2x" : "";
    40.     const char* orientSuffix    = needPortraitSplash ? portraitSuffix : landscapeSuffix;
    41.  
    42.     return [NSString stringWithFormat:@"Default%s%s",orientSuffix, szSuffix];
    43. }
    44.  

    Then, in function OpenEAGL_UnityCallback, we replaced :

    Code (csharp):
    1.  
    2. _splashView = [ [UIImageView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
    3.         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    4.         {
    5.             _splashView.image = [UIImage imageNamed:SplashViewImage(UIInterfaceOrientationPortrait)];
    6.         }
    7.         else
    8.         {
    9.             _splashView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    10.             _splashView.autoresizesSubviews = YES;
    11.         }
    12.        
    13. #ifdef __IPHONE_4_0
    14.         if(   [_splashView respondsToSelector:@selector(setContentScaleFactor:)]
    15.             [[UIScreen mainScreen] respondsToSelector:@selector(scale)]
    16.            )
    17.             [ _splashView setContentScaleFactor: [UIScreen mainScreen].scale ];
    18. #endif
    19.        
    20.         [view addSubview:_splashView];
    21.  
    by the old function we put back :

    Code (csharp):
    1.  
    2. CreateSplashView( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? (UIView*)_window : (UIView*)view );
    3.  

    Our complete code for this sections looks like this :

    Code (csharp):
    1.  
    2. // -----------------------------------------------------------------------------------------------------
    3.     // BUG IN UNITY ON IPAD. THIS IS A TEMPORARY FIX
    4.     NSString *platform = [GetPlatform() substringToIndex:(4)];
    5.    
    6.     if ([platform isEqualToString:@"iPad"])
    7.     {
    8.         // On iPad, we call this function instead, the unity 3.5.2 code
    9.         CreateSplashView( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? (UIView*)_window : (UIView*)view );
    10.     }
    11.     else
    12.     {
    13.         // On all other devices, we call the new unity 3.5.3 code
    14.         _splashView = [ [UIImageView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
    15.         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    16.         {
    17.             _splashView.image = [UIImage imageNamed:SplashViewImage(UIInterfaceOrientationPortrait)];
    18.         }
    19.         else
    20.         {
    21.             _splashView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    22.             _splashView.autoresizesSubviews = YES;
    23.         }
    24.        
    25. #ifdef __IPHONE_4_0
    26.         if(   [_splashView respondsToSelector:@selector(setContentScaleFactor:)]
    27.             [[UIScreen mainScreen] respondsToSelector:@selector(scale)]
    28.            )
    29.             [ _splashView setContentScaleFactor: [UIScreen mainScreen].scale ];
    30. #endif
    31.        
    32.         [view addSubview:_splashView];
    33.     }
    34.     // -----------------------------------------------------------------------------------------------------
    35.  
    Then we build and it should work. It's really a workaround, and unity must fix this. I'm happy to see that I'm not the only one who had this issue!

    Hope this helps!

    Alex
     
  4. davemeta

    davemeta

    Joined:
    Jul 17, 2012
    Posts:
    17
    They forgot to add back the image for non iPhone devices. This is a one-liner fix.

    Code (csharp):
    1.  
    2.     _splashView = [ [UIImageView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
    3.     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    4.     {
    5.         _splashView.image = [UIImage imageNamed:SplashViewImage(UIInterfaceOrientationPortrait)];
    6.     }
    7.     else
    8.     {
    9.         _splashView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    10.         _splashView.autoresizesSubviews = YES;
    11. //THIS IS THE LINE THEY FORGOT
    12.         _splashView.image = [UIImage imageNamed:SplashViewImage(UIInterfaceOrientationPortrait)];
    13. //THIS IS THE LINE THEY FORGOT
    14.     }
    15.  
    16.  
    Or if you are obsessive about clean logic, just replace the whole darn thing with this:

    Code (csharp):
    1.  
    2.     _splashView = [ [UIImageView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
    3.     _splashView.image = [UIImage imageNamed:SplashViewImage(UIInterfaceOrientationPortrait)];
    4.     if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
    5.     {
    6.         _splashView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    7.         _splashView.autoresizesSubviews = YES;
    8.     }
    9.  
     
    Last edited: Jul 17, 2012
  5. Rogetsss

    Rogetsss

    Joined:
    Jul 11, 2012
    Posts:
    12
    Whoa nice find! We didn't have much time to check that out, now your solution is really good!

    Thx!

    Alex
     
  6. davemeta

    davemeta

    Joined:
    Jul 17, 2012
    Posts:
    17
    Glad to help! This was driving us crazy -- I have also submitted the solution to Unity support. Luckily it is very quick to make this change for your production builds, just make sure to add it to your submit checklist until they get a fix in place : )
     
  7. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Official fix will look exactly the same. We working to get it out to the public.
     
  8. CH

    CH

    Joined:
    Jul 4, 2012
    Posts:
    109
    Has this this already been fixed in Unity 3.5.4f1?
     
  9. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    I believe it should come with 3.5.5.
     
  10. johnston

    johnston

    Joined:
    Sep 7, 2013
    Posts:
    1
    I understand the all 3.5.5 below are experiencing this kins of issue and for the above versions they are safe.
     
    Last edited: Sep 7, 2013