So I’ve been experiencing freezes on my Android game, only on my device not in the editor.
The game just freezes. The background music continues to play, some sound effects like rain and thunder continue to play but game itself looks like an image; it’s just frozen.
I’ve successfully been able to pinpoint what method is causing it but I can’t figure out why. On a more interesting note this only started happening when I upgraded to Unity 4.2. With no modification this worked without a problem on 4.1.
[NOTE]
I also want to point out that I have script debugging on and I’m using LogCat to monitor any errors my phone spits out. When the freezing happens there is NOTHING printed out. According to Unity/my device there are no errors.
This is the code that causes the game to freeze after 7-12 minutes of playing:
public IEnumerator MusicRoutine(){
while(true){
if(playingMusic){
musicSource.Stop();
if(shuffle){
int randomNumber = Random.Range(0, (musicList.Length - 1));
lookingForASong = true;
while(lookingForASong){
for(int i = 0;i < whatSongsHaveWePlayedShuffle.Length;i++){
if(randomNumber == whatSongsHaveWePlayedShuffle*){*
-
i = 100;*
-
tempbool = true;*
-
}*
-
if(tempbool == false){*
-
nothingMatched = true;*
-
}else{*
-
nothingMatched = false;*
-
tempbool = false; *
-
}*
-
}*
-
if(nothingMatched){*
-
lookingForASong = false;*
-
nothingMatched = false;*
-
musicSource.clip = null;*
-
yield return null;*
-
yield return null;*
-
musicSource.clip = musicList[randomNumber];*
-
yield return null;*
-
yield return null;*
-
whatSongsHaveWePlayedShuffle[tempIndexNumber] = randomNumber;*
-
tempIndexNumber++;*
-
if(tempIndexNumber >= musicList.Length){*
-
tempIndexNumber = 0;*
-
resetShuffleArrayForWhatSongsHaveBeenPlayed();*
-
}*
-
}else{*
-
randomNumber = Random.Range(0, (musicList.Length - 1));*
-
}*
-
}*
-
}*
-
else{*
-
musicSource.clip = null;*
-
yield return null;*
-
yield return null;*
-
musicSource.clip=musicList[currentTrackID];*
-
yield return null;*
-
yield return null;*
-
currentTrackID+=1;*
-
if(currentTrackID == musicList.Length) {*
-
currentTrackID=0;*
-
}*
-
}*
-
yield return new WaitForSeconds(0.5f);*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
yield return new WaitForSeconds(1f);*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
//we must have a hand full of delays to make sure the clip is playable*
-
if(musicSource.clip.isReadyToPlay){ //im not exactly sure how this check works so we'll keep the delays*
-
musicSource.Play(); //start playing*
-
yield return null;*
-
yield return new WaitForSeconds(musicSource.clip.length + 2.3f);*
-
}else{*
-
//im not sure why we wouldn't be ready but if we still aren't ready lets wait*
-
yield return null;*
-
yield return new WaitForSeconds(3f);*
-
yield return null;*
-
if(musicSource.clip.isReadyToPlay){ //one more check for shiggles*
-
musicSource.Play(); //start playing*
-
yield return null;*
-
yield return new WaitForSeconds(musicSource.clip.length + 2.3f);*
-
}else{*
-
//it's still not ready so something is wrong, lets break out;*
-
break;*
-
}*
-
}*
-
yield return null;*
-
}else{*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
yield return new WaitForSeconds(2f);*
-
yield return null;*
-
yield return null;*
-
yield return null;*
-
}*
-
}*
-
}*
It does not matter if shuffle is true or false.
On a more interesting note if I set playingMusic to false so that it doesn’t actually execute any of the music playing it does NOT freeze. This value was set to false at STARTUP before it was ever able to execute. (It’s a PlayerPref).
Can anyone think of why this is causing my game to freeze?
Thanks