COMPILE ERROR Exception, wrapper dynamic-method, while running with --aot-only

Hi guys,
I have a path stored in a Vector3 JS Array (not built in) generated at runtime, and it works in the editor,
but the object does not move on device iP 3G and shows this exception in the xCode profiler…
also noticably slowing down the app, as it is obviously trying to do it every frame.

This is the error:

ExecutionEngineException: Attempting to JIT compile method ‘(wrapper dynamic-method) UnityEngine.Vector3:Vector3$x (object,object[ ])’ while running with --aot-only.

Any help with explaining what is “aot only” or something related to the Vector3 stuff there would be really appreciated.
I will try to find out myself in the meantime :slight_smile:

Happy new year!

Replace the JS Array with a Vector3[ ] array, or if you need dynamic length, use List.. There’s almost no reason to use Array for anything.

–Eric

I understand, thanks for the quick reply. Is List available in JavaScript?

I will try to convert it to built in. In the meantime I have found out that the error originates in this part of the script

if (pathStarted) {
		
		if (nodeIndex == 0) {
			movementDir = Vector3(npcPath[nodeIndex].x * 5, 0, npcPath[nodeIndex].z * 5) - Vector3(npcPath[nodeIndex + 1].x * 5, 0, npcPath[nodeIndex + 1].z * 5);
		} else {
		movementDir = Vector3(npcPath[nodeIndex-1].x * 5, 0, npcPath[nodeIndex-1].z * 5) - Vector3(npcPath[nodeIndex].x * 5, 0, npcPath[nodeIndex].z * 5);
		}
		timeSoFar += Time.deltaTime;
		
		
		thisTransform.position.x = Mathf.Lerp(thisTransform.position.x, npcPath[nodeIndex].x * 5, timeSoFar/timeTaken);
		thisTransform.position.z = Mathf.Lerp(thisTransform.position.z, npcPath[nodeIndex].z * 5, timeSoFar/timeTaken);
		
		
		if (Vector3.Distance(Vector3(thisTransform.position.x,0,thisTransform.position.z), Vector3(npcPath[nodeIndex].x * 5, 0, npcPath[nodeIndex].z * 5)) <= triggerDistance) {

			if (nodeIndex == 0) {
				if (Vector2(currentPosX, currentPosZ) == Vector2(homeposx, homeposy)) {
                                //Here I generate a new path with A* pathfinding, after the object returns to home position 
					HomeTime();
				} else {
                               //Here I reverse the path, and return the object home
					CellTime();
				}
			}
		
			if (nodeIndex > 0) {
				nodeIndex--;
				timeSoFar = 0;
			}
		}
	
	
		
	}

The error probably originates in this part, where I am asigning the direction

movementDir = Vector3(npcPath[nodeIndex-1].x * 5, 0, npcPath[nodeIndex-1].z * 5) - Vector3(npcPath[nodeIndex].x * 5, 0, npcPath[nodeIndex].z * 5);

Would I have suggested using it otherwise? :wink:

–Eric

Yup, list is available.

If I recall correctly, someone figured out (might have even been Eric) that it should be available without any special imports. If not, it’s in the System.Collections.Generic namespace.

EDIT: I don’t know Eric, you’re a crafty guy >.>

Is Array not that good in terms of performance, when you say there is no reason to use it :slight_smile: ?

Arrays are great for performance, it’s really just a matter of how you use them. List actually wraps a built-in array. It just provides you very easy ways to modify that array (add/remove, some other nice methods) and it’s very fast too. My advice is to use the simplist/easiest API for your scripting then worry about performance/optimizations after.

EDIT: actually, depending on how you would use the array, the List class provides optimizations that make it faster (for example, adding items to an array resizes it, but it doesn’t resize 1 at a time, it doubles the array size so subsequent adds are very fast.)

Allright guys, thanks for your answers, I will look in to the List problematic right away, as I understand it will at least let me run the stuff on device to see the actual performance.
I think the main concern of this thread, as to understand the profiler message, has been solved. Thanks!

Enjoy your Holidays.

JS Arrays are not that great for performance, no, plus you have to worry about casting stuff correctly. And yeah, for some reason you can use List in JS without importing the System.Collections.Generic namespace, not that I’m complaining. While I’m in agreement with “don’t prematurely optimize”, there really is practically no reason to use Array, and several reasons why not, so you might as well just use List to begin with. Or ideally Vector3[ ] if you have a fixed-size array. But Lists are really quite fast, and you shouldn’t wreck your code trying to use Vector3[ ] if it’s easier to use List.

–Eric

Oh, I was thinking this was about built-in arrays (Vector3[ ]) vs List, not JS’s “Array” class. Yeah, don’t touch that; it’s garbage.

Thanks guys, I wonder if this will actually work on iPhone, since I have read that “System.Collections.Generic are not fully supported on the iPhone”? Was it pre unity 3.0 issue?

But clearly here http://answers.unity3d.com/questions/18720/is-new-listt-worse-than-using-clear
it is being used.

Once again: “Would I have suggested using it otherwise? ;)”

–Eric

I have now implemented the List. version of the path array
and also tested it on device. Works perfectly!

Although I cannot use List.Reverse directly, but that is not the topic of this thread.

Thanks a lot guys!

Yeah, sorry to doubt you :slight_smile:
I was just wondering.

Why can’t you use the Reverse method? How are you trying to invoke it?

Well, actually just like this

pathList.Reverse();

and got this error:

Assets/Scripts/PlayerManager.js(335,18): BCE0019: ‘Reverse’ is not a member of ‘Boo.Lang.List’.

:slight_smile: in order to move on, and not spend all day figuring it out i set it up manually, although would rather use a built in method of course.
Thanks for asking.

for (var r1 : int = 1; r1 <= pathList.Count; r1++) {
			pathListRev.Add(pathList[pathList.Count - r1]);
	}
	pathList = pathListRev;

other associated methods work just fine - Clear(), Add(), Sort() , … so should Reverse I think.

I would expect Reverse to work, it’s been there since .NET 2.0. I just double-checked the Mono-specific API and it agrees: http://www.go-mono.com/docs/index.aspx?link=M%3ASystem.Collections.Generic.List`1.Reverse()

Do “import System.Collections.Generic;”…seems that Lists are only partially supported without that.

–Eric

Thanks for the info Eric. I’ll have to try harder to remember this quirk for List.