Unfortunate Error Message.

I have a fairly simple hockey game that I’ve created and intend to showcase at an event this Thursday. Unfortunately I sometimes get the following error message and the game freezes.

!CompareApproximately (SqrMagnitude (q), 1.0F, Vector3f::epsilon)

I don’t know how to recreate the problem consistantly.

From what I’ve read, this is an internal Unity problem but I need this demo to work and not freeze when I have a group of people watching or playing it.

Does anyone know what part of a game this error message would be reponding to? I could always rework the code or assets to avoid the problem.

I have sent the scene in as a bug.

Any suggestions?

The error message you get can safely be ignored.

The freeze is in no way related to it, there is only one reason why a freeze can happen and that is if you write a loop which never terminates.

eg.
while (true)
{ }

Hmmm…

Unfortunately that doesn’t really make sense.

The game plays fine for anywhere from 1 minute to 20 minutes and then the ice disappears and the movement stops and that error message comes up at the bottom. I have never had a freeze that wasn’t accompanied by that error message.

The game is free standing in that it all takes place at one time in one window. Whatever you can do in the first few seconds, you can do for the rest of the game without anything new being introduced.

The game has 7 inputs.
2 for passing left and right
2 for shooting on goal
2 for starting and stopping defensemen on animated movement path
1 for starting and stopping a goalie on an animated movement path

The only other element, besides the static ice, walls and net object, is a looping organ track.

I have tried for over on hour to recreate the problem with keystrokes but I haven’t been able to consistently reproduce the error.

I have also seen this error message

!CompareApproximately (SqrMagnitude (m_LocalRotation), 1.0F)

if that helps at all.

Following your thought above in light of Joachim’s comments, have you verified that at the point the freeze occurs that you’re not locked in a never-ending loop somehow?

I went though all of my scripts and none of them have loops or use while’s.

The only one I found that may cause a problem is this one

var playerposition = 3;
var aPosition : Vector3; //new position
var bPosition : Quaternion; //new rotation
var cPosition : Vector3; //current position
var dPosition : Quaternion; //current rotaion
private var nextmove = 0.0;
var stoptime = .5;
var counting1 = 0.00;
var nextstep = 0.00;
var movetime = .01;
var counting1rate = .06;

aPosition = Vector3(0, 1.5, 0);
bPosition = Quaternion.EulerAngles(0, 0, 0);

function Update () { 
   	if (Input.GetAxis ("PassLeft")  Time.time > nextmove) {
   		nextmove = Time.time + stoptime;
		playerposition = playerposition - 1;
			if (playerposition == 0){
				playerposition = 5;
			}	
		PlayerMoveSetUp (); 
		}
	else if (Input.GetAxis ("PassRight")  Time.time > nextmove) {
   		nextmove = Time.time + stoptime;
		playerposition = playerposition + 1;
			if (playerposition == 6){
				playerposition = 1;
			}	
		PlayerMoveSetUp (); 
		}
	transform.position = Vector3.Lerp(cPosition, aPosition, (counting1));   
	transform.rotation = Quaternion.Slerp(dPosition, bPosition, (counting1));    

	if (Time.time > nextstep){
		counting1 = counting1 + counting1rate;
		nextstep = Time.time + movetime;
	}
	
}

function PlayerMoveSetUp () {

		cPosition = transform.position;
		dPosition = transform.rotation;

		counting1 = 0.00;

		 if (playerposition == 1){
			aPosition = Vector3(-10, 1.5, 6); //position
			bPosition = Quaternion.EulerAngles(0, .85, 0); //rotation
		}
		else if (playerposition == 2){
			aPosition = Vector3(-6, 1.5, 5);
			bPosition = Quaternion.EulerAngles(0, .5, 0);
		}
		else if (playerposition == 3){
			aPosition = Vector3(0, 1.5, 0);
			bPosition = Quaternion.EulerAngles(0, 0, 0);
		}
		else if (playerposition == 4){
			aPosition = Vector3(6, 1.5, 5);
			bPosition = Quaternion.EulerAngles(0, -.5, 0);
		}
		else if (playerposition == 5){
			aPosition = Vector3(10, 1.5, 6);
			bPosition = Quaternion.EulerAngles(0,-.85, 0);
		}
	}

I did find one potential error. In the function PlayerMoveSetUp I had been resetting

counting1 = 0;

and I changed it to

counting1 = 0.00;

Could that have somehow caused the freeze?

It seems unlikely given that it doesn’t immediately cause a crash when I use it.

I tried the game with the code change and no luck. It still froze.

I have the following scripts in the game.

A shoot puck script that creates a puck and sends it forward.

A puck hits denfender script (this adds one point to a block points script)

A puck hit goalie script (this adds one point to a save shot script)

A puck hit net script (this adds one point to the goals script)

A player move left or right script (posted above)

A defender stop or start script (on an animation path)

A goalie stop or start script (on an animation path)

And that’s it.

They all pretty much just do one thing except for the player move script already posted.

Is playerposition ever not 1-5? since you’re using else if statements one of those conditions have to be true. If you switched it to regular if statements or a switch (does Javascript have those?) and set the default to do nothing then you may not have a problem.

I guess the error could also be in the Update function and the if - else if statements there. But it seems more likely to be the other.

No; using 0 or 0.00 normally makes no difference. The only time it would matter is when defining a variable…if you use 0, the variable is defined as an integer (unless you specifically say otherwise), and using 0.0 makes it a float.

I don’t think I see anything there that would cause a freeze. A couple of hints that would save some typing, though: statements like “playerposition = playerposition + 1;” can be better written as “playerposition += 1;”, or in the case of simple incrementing like that, “playerposition++;” (and “playerposition–;” for decrementing). You also might find using the switch/case construct (yes, Javascript has that) more convenient than a series of if/if else statements.

–Eric

Thanks for the tips. I’m a self taugh (much assisted) programer with a minor REALbasic background so I never really learned all of the time saving options.

I updated the script and removed the elses and changed the == to < and > to keep my values in range but it still eventually freezes.

I got distracted while testing the game and when I came back the ice had disappeared but the game had not frozen. None of my code mentions the ice so I have no idea why this happened.

I’m going to give the scoring system a closer look but I doubt that that is the problem as I have used those scripts in other games.

I’ve added a screen shot of the game in working mode so you can get and idea of how the game works.

Given that the script you cited doesn’t contain any loops, why is it that you think that one in particular might cause problems? Was it just the =0 versus =0.0 that struck you as a possible issue? (as mentioned above that’s not a problem) After giving it a quick scan I too fail to see anything obviously wrong with the script and I’m a bit stuck as to what your next steps ought to be. Perhaps a brute force approach is needed here, put a bunch of Debug.Log() statements in your code or something, that way when you run the game and it freezes you’ll have an idea as to what code is executing when the freeze occurs.

I’ll give that a try but when the games freezes, it takes Unity with it.

Will the Debug.Log() still work if Unity freezes also?

Are you doing anything with OnCollision* or OnTrigger* where you might also move one of the objects involved in the collision/trigger? There is a way that this can cause an infinite loop that takes down Unity. For example, if in OnTrigger() you are moving one of the objects to a specific location, then that move could trigger an OnTrigger() that will then move the object back to that position, which will … You get the idea. Not that I know anything personally about this scenario :sweat_smile:

I have had some other situation where Unity appears to go down for no reason, but unfortunately I cannot think of them right now :frowning: Pay extra attention anyplace where you are interacting with the physics engine but are making modifications that the physics engine will take into account.

My only collision code is like this

var score : ScoreGoalie;

function OnCollisionEnter (col : Collision) { 
	if (col.other.gameObject.CompareTag ("Puck")) {
		if (audio  !audio.isPlaying) { 
 			audio.Play (); 
 		}
 		score.AddToScore ();
	} 
   }

The next scrpt starts and stops the opposing players. Any concerns with it?

var curnum = 1;
var stoptime = .5;
private var nextshot = 0.0;

function Update () { 
   	if (Input.GetAxis ("Defender2")  Time.time > nextshot) {
   		nextshot = Time.time + stoptime;
   	 	
		 if (curnum == 2){
			animation["Default"].speed = 1;
			curnum = 1;
		}
		else if (curnum == 1){
			animation["Default"].speed = 0;
			curnum = 2;
		}
	}
}

That’s pretty much it for the game besides the scoring.

Is it possible that the mesh for the ice object (the ice disappears just before a freeze) is some how doing the damage? It’s just a simple plane but I could exchange it.

just a crazy idea… sounds like this is all in editor? have you built a standalone to see if the same thing happens? maybe something got messed in your unity install or there’s something in the project but not in the game that unity doesn’t like.

Unfortunately I usually test the built version. I will try a rebuild though and see if that makes a difference.

Well, just change

      if (curnum == 2){ 
         animation["Default"].speed = 1; 
         curnum = 1; 
      } 
      else if (curnum == 1){ 
         animation["Default"].speed = 0; 
         curnum = 2; 
      }

to

      curnum = 1-curnum;
      animation["Default"].speed = curnum;

Not that the functionality will change or anything. Sorry…I’m not trying to be annoying. :slight_smile: :sweat_smile:

The ice thing is weird…obviously that shouldn’t happen. What properties does it have? The only thing I can think of is that it’s being affected by physics somehow in some way that it shouldn’t.

–Eric

Not annoying at all. I prefer to be more effcient. Thanks for the tip.

Here are the Ice properties.

In the first script you posted you do:

aPosition = Vector3(0, 1.5, 0);
bPosition = Quaternion.EulerAngles(0, 0, 0);

but you dont do that for c d, seems like you should initialize them in the same way. Not initializing the rotation could cause the assert you were getting.

Also i would move that initialization code into the Start function instead of global scope for clarity.

How about removing the rigidbody on the ice altogether? You have Is Kinematic checked, so it doesn’t seem like it would make a difference, but you shouldn’t need the rigidbody for anything in that case (just the collider), so give it a try.

–Eric

I will try both of the suggestions.

A bit of new info. While I was running a recent test. The ice eventually disappeared but the game continued. It froze when I hit the shoot puck key. The script I use for shooting the puck is based on the one from the original unity demo scene so I doubt it would be causing the error but here it is.

var ball : Rigidbody;
var velocity = 30.0;
var fireRate = 1.0;
private var nextFire = 0.0; 
	
function Update (){
	 if (Input.GetAxis ("Shoot1")  Time.time > nextFire) {
	 	nextFire = Time.time + fireRate;
		var shoot : Rigidbody = Instantiate (ball, transform.position, transform.rotation);
		shoot.velocity = transform.rotation * Vector3.fwd * velocity;
     } 
	
}

Thanks for everyones continued help. I’m showing this game at a Innovation’s Expo tomorrow so I really hope I can solve the problem. For clarification I know that this game isn’t ground breaking. I have been developing the game with a group of people with disabilities and we are looking at making it available to others. They love hockey and they love the game (until it freezes).