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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

iOS screenshot system out of memory error

Discussion in 'Scripting' started by glennseso, Nov 21, 2012.

  1. glennseso

    glennseso

    Joined:
    Nov 11, 2011
    Posts:
    34
    hi everyone!
    i'm making an app that use a lot high poly models and this is using a lot of memory (about 300 mb ram).
    it's running great and now i created a screenshot system.
    i'm using
    Code (csharp):
    1.  
    2. Application.CaptureScreenshot("/screenshots/" + _screenShotName +".png");
    3.  
    for capture screenshot and I made a thumbnail preview function called on OnGUI.

    The app show one thumbnail at time and user can change by tabbing the prev/next arrow.

    I used just one
    Code (csharp):
    1.  
    2. private Texture2D _tempTexture;
    3.  
    and all screenshots are load in this texture.

    this is the function:

    Code (csharp):
    1.  
    2. private void drawThumbnail()
    3.  
    4. {
    5.     if(GUI.Button(new Rect(118,408,29f/2,47/2),GUIManager.Instance.GetTexture("back"), GUIStyle.none))
    6.     {
    7.         if(_screenShotIndexForPreview > 0)
    8.         {
    9.             _screenShotIndexForPreview--;
    10.  
    11.             StartCoroutine (loadScreenShotPNG(_screenShotNames[_screenShotIndexForPreview]));
    12.         }
    13.     }
    14.  
    15.  
    16.     if(GUI.Button(new Rect(320,408,29f/2,47/2),GUIManager.Instance.GetTexture("next"), GUIStyle.none))
    17.     {
    18.         //if is not the last image
    19.         if(_screenShotIndexForPreview < _screenShotNames.Length - 2)
    20.         {
    21.             _screenShotIndexForPreview++;
    22.  
    23.             StartCoroutine (loadScreenShotPNG(_screenShotNames[_screenShotIndexForPreview]));
    24.         }
    25.     }
    26.  
    27.     if(_tempTexture != null)
    28.     {
    29.         GUI.DrawTexture(new Rect(xScreen,yScreen,   xScale/2,  yScale /2),_tempTexture);
    30.     }
    31. }
    32.  
    33.  
    34. IEnumerator loadScreenShotPNG(string pngName)
    35. {
    36.     string imageFileURL;
    37.  
    38.     imageFileURL= "file://" + path + "/screenshots/" + pngName + ".png";
    39.  
    40.     imageFileURL = imageFileURL.Replace(" ", "%20");
    41.  
    42.     WWW _www = new WWW(imageFileURL);
    43.  
    44.     yield return _www;
    45.     //the actual size of screenshot is 1024x768
    46.     //I tryed various smaller sizes but it make no diffrence
    47.     _tempTexture = new Texture2D(512, 512);
    48.  
    49.     _www.LoadImageIntoTexture(_tempTexture);
    50. }
    51.  
    This works. The problem is that the app crashes after some next/back.

    I think this is a memory problem because of the repeatedly allocation/deallocation of textures.

    I want to know if exist a better way to do this.

    Att.
     
  2. glennseso

    glennseso

    Joined:
    Nov 11, 2011
    Posts:
    34
    Anyone knows some app made in Unity that have this feature? I haven't found anything.

    Att.