Search Unity

memory leak in [url]www.texture[/url]

Discussion in 'Scripting' started by StephanA, Apr 2, 2008.

  1. StephanA

    StephanA

    Joined:
    Mar 26, 2008
    Posts:
    3
    Hi!

    i just run into next trouble :?

    please create a new scene and attach this script to the camera ( or create an empty gameobject )

    Code (csharp):
    1.  
    2. // press spacebar to change texture
    3.  
    4. private var cube : GameObject;
    5. private var tex_nr = 1;
    6.  
    7. function Start(){
    8.     var lightGameObject = new GameObject("Light");
    9.     lightGameObject.AddComponent(Light);
    10.     lightGameObject.transform.position = Vector3(0,5,-10);
    11.      
    12.     cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    13.     cube.transform.position = Vector3(0,1,-8);
    14.     cube.transform.eulerAngles = Vector3(0,180,0);
    15.     Get_Texture();
    16. }
    17.  
    18. function Update () {
    19.     cube.transform.Rotate(0,Time.deltaTime*10,Time.deltaTime*10);
    20.     if (Input.inputString == " "){
    21.         Get_Texture();
    22.     }
    23. }
    24.  
    25. function Get_Texture(){
    26.     www = new WWW("http://www.abramedia.de/unity/screen" + tex_nr + ".jpg");
    27.     yield www;
    28.     cube.renderer.sharedMaterial.mainTexture = [url]www.texture;[/url]
    29.     tex_nr++;
    30.     if (tex_nr > 6) {tex_nr = 1;}
    31. }
    or watch it online:

    http://www.abramedia.de/unity/texture_test.html

    press spacebar to change the texture on the cube.

    please watch this script in action and look at the memory increasing... why is that?

    i have used ImmediateDestroy on www.texture but this is no solution.

    any hints or ideas?

    Stephan
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    .texture creates a new Texture instance each time you call it.
    Instead you probably want to replace the contents of an existing Texture using www.LoadImageIntoTexture();
     
  3. StephanA

    StephanA

    Joined:
    Mar 26, 2008
    Posts:
    3
    thanks Joachim!

    that seemed to work!

    Stephan