LoadLevel causes non-dev compiled game crash on Android

Hello all,

I’ve read everything there is in the Unity Answers and on the forums about this problem. It seems very wide spread.

Even with the simplest programs a LoadLevel will (may) cause my game to compiled as a non-dev build to crash. I wrote “may” because sometimes it actually works, but very rarely. The exact same program compiled as a dev build works exactly as expect with good load times and no crashing.

I’ve tried everything that was suggested in any of the answers to any of the similar problems listed in the forums or on the Unity Answers pages including:

  1. isolating the LoadLevel in a separate function that is called by a button press
  2. including a yield in the isolated function to ensure the level is loaded

function loadALevel(){
Application.LoadLevel(“startPlay”); // load the game level.
while(Application.isLoadingLevel) yield;
}

  1. tried wrapping the function call in a boolean to ensure that it is not being called multiple times with each button push

if(noPress){ //try this
noPress = false;
loadALevel();
}//try this

  1. tried loading an empty level and then using a LoadLevelAdditive() to load the actual level

  2. tried upgrading to the latest Unity

In it’s simplest form, this is how I am trying to load a new scene:

if (GUI.Button( Rect( Screen.width/2-250, Screen.height/2+30, 150, 50), “Mode A”)){
isLoading = true;
PlayerPrefs.SetString(“gameMode”,“MODEA”);

audio.clip = buttonSounds[Random.Range(0,buttonSounds.length)];
audio.Play();

Application.LoadLevel(“startPlay”); // load the game level.
}

Could there be an issue with the PlayerPrefs.SetString not having finished writing before the LoadLevel is called? Is there anything I can do about it if that’s what it is?

I am testing on a Samsung Galaxy Tab 2 (pushed on rather than emulated) and using Unity 3.5.6f4.

Thanks for any assistance. This is my first Unity game and I’m looking forward to getting it out.

I’ve posted this in the Android section as well, but have not had a response. Hoping someone here can help:

Hello all,

I’ve read everything there is in the Unity Answers and on the forums about this problem. It seems very wide spread.

Even with the simplest programs a LoadLevel will (may) cause my game to compiled as a non-dev build to crash. I wrote “may” because sometimes it actually works, but very rarely. The exact same program compiled as a dev build works exactly as expect with good load times and no crashing.

I’ve tried everything that was suggested in any of the answers to any of the similar problems listed in the forums or on the Unity Answers pages including:

  1. isolating the LoadLevel in a separate function that is called by a button press
  2. including a yield in the isolated function to ensure the level is loaded

function loadALevel(){
Application.LoadLevel(“startPlay”); // load the game level.
while(Application.isLoadingLevel) yield;
}

  1. tried wrapping the function call in a boolean to ensure that it is not being called multiple times with each button push

if(noPress){ //try this
noPress = false;
loadALevel();
}//try this

  1. tried loading an empty level and then using a LoadLevelAdditive() to load the actual level

  2. tried upgrading to the latest Unity

In it’s simplest form, this is how I am trying to load a new scene:

if (GUI.Button( Rect( Screen.width/2-250, Screen.height/2+30, 150, 50), “Mode A”)){
isLoading = true;
PlayerPrefs.SetString(“gameMode”,“MODEA”);

audio.clip = buttonSounds[Random.Range(0,buttonSounds.length)];
audio.Play();

Application.LoadLevel(“startPlay”); // load the game level.
}

Could there be an issue with the PlayerPrefs.SetString not having finished writing before the LoadLevel is called? Is there anything I can do about it if that’s what it is?

I am testing on a Samsung Galaxy Tab 2 (pushed on rather than emulated) and using Unity 3.5.6f4.

Thanks for any assistance. This is my first Unity game and I’m looking forward to getting it out.

You could try to debug your device with a log viewer like aLogcat to see if there’s some log crash (or your own Debug.Log info).

Though we don’t know your game logic so we cannot be more useful until you give us more code/ detail about your before/later code and what is expected in the loaded level. Using LoadLevel is synch as far as I know, so probably you will not get any code run after it’s called. You talked about a SetString not having finished but I think it is synch so I expect it has been finished just after the call (you have a Save after all the Sets, right)…

Thanks, Francesco.

I’ve been looking through the log and I can see the error is a “Fatal signal 11 (SIGSEGV) at 0x00000005 (code=1)”

Later in the log file is: “Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x00000005”

So there is something being destroyed or is no longer accessible. But I have no idea what it could be…I’ll attach the trap in the morning if someone out there know how to analyze it.

The error unfortunately is very poor. Need to double check your scripts, may be something is assuming that an object exists while it’s not or similar issue in some of your new level calls, did you try to load a new blank level to be sure it doesn’t depend on your loaded level?

Actually this problem is popping up all over the forums now with different titles on the original thread. Starting to wonder if it’s not something in the latest Unity3d. Might be related to GUI buttons. I’m going to make the most simple version I can. 2 scenes each with a button that leads to the other and see if it still crashes.

Here it is in it’s absolute simplest form, 2 scenes, one calls the other, and I still get a crash…Fatal signal 11

firstWindow has the following script attached to the main camera

function OnGUI () {
	if (GUI.Button( Rect( Screen.width/2+90, Screen.height/2+30, 150, 50), "Second Window")){
		Application.LoadLevel("secondWindow"); // load the game level.
	}			
}

secondWindow has the following script attached to the main camera

function OnGUI () {
	if (GUI.Button( Rect( Screen.width/2+90, Screen.height/2+30, 150, 50), "First Window")){
		Application.LoadLevel("firstWindow"); // load the game level.
	}			
}

and the result is a crash. unity 3.5.6f4 is broken! Or my Galaxy Tab 2 is…one or the other.

Here it is in it’s absolute simplest form, 2 scenes, one calls the other, and I still get a crash…Fatal signal 11

firstWindow has the following script attached to the main camera

function OnGUI () {
	if (GUI.Button( Rect( Screen.width/2+90, Screen.height/2+30, 150, 50), "Second Window")){
		Application.LoadLevel("secondWindow"); // load the game level.
	}			
}

secondWindow has the following script attached to the main camera

function OnGUI () {
	if (GUI.Button( Rect( Screen.width/2+90, Screen.height/2+30, 150, 50), "First Window")){
		Application.LoadLevel("firstWindow"); // load the game level.
	}			
}

and the result is a crash. unity 3.5.6f4 is broken! Or my Galaxy Tab 2 is…one or the other.

Please do not post duplicate topics; it’s against the rules. It’s OK to bump your thread after a day or so, preferably with new information.

–Eric

This has been reported as a bug using the Unity Bug report tool in the help menu.

Downgrading Unity to Unity 3.5.2 fixes this issue.

Saved me some time there :slight_smile: Thanks.

I encountered this issue a few days ago in Unity 3.5.6 and yea, it seems to go away with the removal all of my OnGUI code.

3.5.2 it is if we need it :slight_smile:

I experienced the exact same problem in 3.5.6f4. Thanks for this information, otherwise I might never have found the cause. I’ll try to submit a bug report as well.