Question by
KouYang · Jul 24, 2018 at 06:25 AM ·
texturevideodisplaymemory-leak
Apparent Memory Leak during texture change
Hi,
I'm trying to create a video display on my project, and it should change to a random video every time I press the "I" key. I've been able to make it choose a random video out of an array, but every time the video is swapped, the game gets slower and slower, up to almost crashing on the third or fourth video.
Follows the code I've been using to swap the video:
//=================================================================================
// © 2016 Scott Durkin, All rights reserved.
// By Downloading and using this script credit must
// be given to the creator know as "Unity3D With Scott".
// YouTube Channel: https://www.youtube.com/channel/UC9hfBvn17qSIrdFwAk56oZg
//=================================================================================
public MovieTexture movieDisplay;
public MovieTexture[] movieListLevel1;
public MovieTexture[] movieListLevel2;
public MovieTexture[] movieListLevel3;
public int movieStartingLevel = 1;
private int movieNumber = 0;
void Start ()
{
GetComponent<RawImage>().texture = movieDisplay as MovieTexture;
movieDisplay.Play();
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.P) && movieDisplay.isPlaying)
{
movieDisplay.Pause();
}
else if (Input.GetKeyDown(KeyCode.P) && !movieDisplay.isPlaying)
{
movieDisplay.Play();
}
if (Input.GetKeyDown(KeyCode.I))
{
if (movieStartingLevel == 1)
{
// movieStartingLevel = movieStartingLevel + 1
// Random array item
int myRandomMovie = Random.Range(0, movieListLevel1.Length);
movieDisplay = (movieListLevel1[myRandomMovie]);
Debug.Log("<b>Playing movie number <color=red>" + myRandomMovie + "</color></b>");
Debug.Log("Next level is level " + movieStartingLevel);
// Change Movie Texture that's being shown to new MovieTexture.
GetComponent<RawImage>().texture = movieDisplay as MovieTexture;
// Play movie.
movieDisplay.Play();
}
}
}
Any help is appreciated.
Thank you,
Kou.
Comment