View Issue Details

IDProjectCategoryView StatusLast Update
0016912Runner[All Projects] FunctionsPublic2018-02-06 11:41
ReporterYellowAfterlifeAssigned ToRussell Kay 
PriorityHighSeverityA - Crash/HangReproducibility100%
Status ClosedResolutionNo Change Required 
PlatformWindowsOSWindows 8OS Version8.1
Product Version 
Target VersionFixed in Version 
Summary0016912: Functions: User-defined array_get function overrides [@] operator? [and crashes the game]
DescriptionConsider the following. There is a function named array_get, which, as you may have guessed, pulls a value out of the array. The code is rather straightforward,
#define array_get
/// array_get(this, index:Int):T
var this = argument[0], index = argument[1];
show_debug_message("array_get(" + string(this) + ", " + string(index) + ")");
return this[@index];

(show_debug_message added for clarity)
But what happens on the call is the most interesting - instead of pulling a value out of array, the function recurses into itself and the game process dies to a stack overflow. To further confirm the fact of recursion, changing "index" to "index + 1" will display rapidly increasing stack depth to the point of crash.

This is not exactly a documented feature, is it?
1.4 Found In1.4.1496
2.x Runtime Found In
2.x Runtime Verified In

Activities

YellowAfterlife

2015-01-03 01:25

Developer  

array_get.gmz (21,444 bytes)

YellowAfterlife

2015-01-06 05:16

Developer   ~0034966

My further research has shown that there are similar functions for other access operators. I'd like to suggest these to be included in built-in function lists (but not auto-completion) to both secure them from being overriden and to allow easier use from user-defined code (for example, you could do array_get(get_some_array(), column) instead of having to assign array to an intermediate variable).

Russell Kay

2015-01-10 17:22

Manager   ~0035119

There are several built in functions that are used for implementing the array accessors - they have now been added so a Game Script cannot be called that - at the moment though you can still call an Extension function that (and override the built in function)... we really should fix that to disallow that behaviour... we will consider that.

YellowAfterlife

2015-01-11 04:48

Developer   ~0035123

To add here, a ds_list accessor function does something that is not possible to do with built-in functions - it expands the list if needed, unlike the ds_list_replace function that will only change the existing indexes.

I have also discovered that adding a function to the extension file without an implementation exposes it for use without crashing the game, but I would very much prefer to see these to in the built-in function list (similar to action_* group).

Russell Kay

2017-11-27 13:28

Manager   ~0056798

This has been mitigated through various error messages and is still possible but difficult to do - closing