Mantis

View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0016912Runner[All Projects] FunctionsPublic2015-01-03 01:252017-11-27 13:28
ReporterYellowAfterlife 
Assigned ToRussell Kay 
PriorityHighSeverityA - Crash/HangReproducibility100%
StatusResolvedResolutionNo Change Required 
PlatformWindowsOSWindows 8OS Version8.1
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 Version1.4.1496
2.x Runtime Version
2.x Runtime Version Verified In
Attached Files? file icon array_get.gmz [^] (21,444 bytes) 2015-01-03 01:25

- Relationships

-  Notes
(0034966)
YellowAfterlife (Developer)
2015-01-06 05:16

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).
(0035119)
Russell Kay (Manager)
2015-01-10 17:22

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.
(0035123)
YellowAfterlife (Developer)
2015-01-11 04:48

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).
(0056798)
Russell Kay (Manager)
2017-11-27 13:28

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


Copyright © 2000 - 2017 MantisBT Team
Powered by Mantis Bugtracker