iOS argument incorrect type - crash

hangred

Member
I am running the following code fine on both Windows and MacOS. It crashes, however, when I run on iOS. The iOS error states "instance_create_layer argument 2 incorrect type (undefined) expecting a Number (YYGF)).
.
I have paraphrased the code for brevity.

global.object_array[0] = obj_one;

var inst;
if instance_exists(global.object_array[0])
{
obj_one.x = global.location_array[0].x;
obj_one.y = global.location_array[0].y;
}
else
{
inst = instance_create_layer(global.location_array[0].x, global.location_array[0].y, "Layer", global.object_array[0]);
global.object_array[0].sprite_index = global.sprite_array[1,2];
global.object_array[0].image_index = 0;
}


I am running:
IDE 2.1.5.322
Runtime 2.1.5.246
I have tried both Xcode 9 and 10 beta as well as the last iOS 11 and now iOS 12. All the same error.
 

chamaeleon

Member
I am running the following code fine on both Windows and MacOS. It crashes, however, when I run on iOS. The iOS error states "instance_create_layer argument 2 incorrect type (undefined) expecting a Number (YYGF)).
.
I have paraphrased the code for brevity.

global.object_array[0] = obj_one;

var inst;
if instance_exists(global.object_array[0])
{
obj_one.x = global.location_array[0].x;
obj_one.y = global.location_array[0].y;
}
else
{
inst = instance_create_layer(global.location_array[0].x, global.location_array[0].y, "Layer", global.object_array[0]);
global.object_array[0].sprite_index = global.sprite_array[1,2];
global.object_array[0].image_index = 0;
}


I am running:
IDE 2.1.5.322
Runtime 2.1.5.246
I have tried both Xcode 9 and 10 beta as well as the last iOS 11 and now iOS 12. All the same error.
Have you stored a "location" (an instance of some object that has x and y variables) in location_array[0]?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
If an instance of "obj_one" does not exist in the room, then you cannot get any x/y value (or any other value) from it. I'm not sure why this would work on Windows, as it really shouldn't, but I suspect it's related to the integer object IDs and the values of keywords. The error is not an iOS issue, it's a code issue, so you need to fix it to get the correct coordinates. Also, make sure that there is a layer called "Layer" in your game room, although I don't think that's the real issue here...
 

chamaeleon

Member
If an instance of "obj_one" does not exist in the room, then you cannot get any x/y value (or any other value) from it.
I was tripped up by it at first too, but the code is complaining about location_array[0], not object_array[0]. And no code is shown that tells us how/if/when location_array is initialized/updated.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I was tripped up by it at first too, but the code is complaining about location_array[0], not object_array[0]. And no code is shown that tells us how/if/when location_array is initialised/updated.
Ooops! Indeed! Thanks for pointing that out to me... More info on where the location array is initialised would definitely help.
 

hangred

Member
Ooops! Indeed! Thanks for pointing that out to me... More info on where the location array is initialised would definitely help.
Are you saying the location array is the issue? Where is "argument 2" according to the error code? In instance_create_layer(), is it (arg0,arg1,arg2,arg3) when reading the error code?
 

TheouAegis

Member
Is there a layer called "Layer" in your room?

Is everybody sure he doesn't have to actually fetch the layer ID for iOS exports?
 

chamaeleon

Member
Are you saying the location array is the issue? Where is "argument 2" according to the error code? In instance_create_layer(), is it (arg0,arg1,arg2,arg3) when reading the error code?
Argument 2 would be "global.location_array[0].y". And if you have not put a valid instance in global.location_array[0] you will get an error if you attempt to access an instance variable for this undefined instance.
 

TheouAegis

Member
Oh yeah, the error messages refer to arguments going from 1 to n, while scripts themselves go from 0 to n. Stupid programmer brain-farts.

Then yeah, it's as they said.

And before OP replies with "why did I get an error on argument 1", arguments are read in reverse in many GM functions. Really irritating when you throw ++ or -- in your arguments. lol
 

hangred

Member
Argument 2 would be "global.location_array[0].y". And if you have not put a valid instance in global.location_array[0] you will get an error if you attempt to access an instance variable for this undefined instance.
This was helpful!! I hard coded the global.location_array and the error went away. Not sure why Windows and Mac OS are ok with me assigning an array like this and iOS is not:
global.location_array[0] = obj_location_1;
 

chamaeleon

Member
This was helpful!! I hard coded the global.location_array and the error went away. Not sure why Windows and Mac OS are ok with me assigning an array like this and iOS is not:
global.location_array[0] = obj_location_1;
Is obj_location_1 an instance that exist in the room so that you can query its x and y variables or is it an object in your resource tree?
 

hangred

Member
Is obj_location_1 an instance that exist in the room so that you can query its x and y variables or is it an object in your resource tree?
Yes. As mentioned this works fine in the Windows and Mac OS builds. Perhaps the GameMaker iOS compile does a different kind of reference?
 

chamaeleon

Member
Yes. As mentioned this works fine in the Windows and Mac OS builds. Perhaps the GameMaker iOS compile does a different kind of reference?
This is kind of fundamental, so I kind of doubt it.. If I were you'd try to debug this by using show_debug_message() (or whatever means is easiest for debugging iOS..) at various points in the code to verify that global.location_array[0] contains a valid instance id, and that referencing its x and y coordinates yields expected results. Maybe there's some kind of order of operations issue with initialization, or something along those lines. Unless you're happy with what you have at the moment.
 

TheouAegis

Member
I'm stumped...

Even if obj_location_1 didn't have a valid instance, it should be throwing an "no instance exists" error, not an illegal argument error.

You cannot accidentally declare var x and var y, but even if you accidentally declared var global.location_array if that was even possible, you'd get an "undeclared variable" error.

If he somehow set obj_location_1 to undefined or set global.location_array[0] to undefined, it would default to a value of 0 on Windows and run accordingly. Whether or not it treats <undefined>.y as (0).y on iOS, I don't know. It's something to look into.

But I can't recreate his error at all, at least in GMS1. So that'd suggest it's a GMS2 error. Which, by the way, is on version 2.2 now, not 2.1 (according to the website).
 
Last edited:
Top