Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-Game: array_copy() when "src_index" is invalid will silently crash the game, should show an error #7917

Closed
gm-bug-reporter bot opened this issue Oct 6, 2024 · 9 comments
Assignees
Labels
documentation Improvements or additions to documentation are required by this issue project This issue has a sample project attached runner-bug In-game bugs with the "GameMaker Studio 2" runtimes
Milestone

Comments

@gm-bug-reporter
Copy link

Description

it should either crash with an error message or have missing entries filled with zeros, like it is the case for using an out of bounds index for dest_index.

Steps To Reproduce

var src_array = [ 1, 2, 3 ]

var dest_array = [ 4, 5, 6 ]
array_copy(dest_array, 4, src_array, 1, 1)
show_debug_message($"dest_ind out of bounds, filled with 0's {dest_array}")

var dest_array = [ 4, 5, 6 ]
array_copy(dest_array, 1, src_array, 4, 1)
show_debug_message($"src_index out of bounds, will not get printed {dest_array}")

Which version of GameMaker are you reporting this issue for?

IDE v2024.8.1.171 Runtime v2024.8.1.218

Which operating system(s) are you seeing the problem on?

Windows 10.0.19045.0

Which platform(s) are you seeing the problem on?

Windows

2cfe6c82-021f-460d-af68-629cc27de693

@gm-bug-reporter gm-bug-reporter bot added project This issue has a sample project attached runner-bug In-game bugs with the "GameMaker Studio 2" runtimes labels Oct 6, 2024
@stuckie stuckie moved this from Triage to Todo in Team Workload Oct 7, 2024
@stuckie stuckie added this to the 2024.11 milestone Oct 7, 2024
@DiasFranciscoA
Copy link

The behavior you're observing is expected. When the dest_index is out of bounds, the destination array is expanded, and the new elements are filled with zeros. This happens because we're writing to indices that don't exist, which triggers the array to grow. While this behavior might seem unusual, it is consistent with legacy design.

However, the scenario you're describing involves an out-of-bounds src_index—meaning you’re trying to read from an invalid index in the source array. In this case, we don’t expand the array or fill it with zeros because accessing a non-existent index should not alter the source array. Instead, this scenario should result in an error or be safely ignored. Expanding the source array to accommodate an invalid read would not be the correct behavior.

@DiasFranciscoA DiasFranciscoA moved this from Todo to In Progress in Team Workload Oct 11, 2024
@DiasFranciscoA
Copy link

DiasFranciscoA commented Oct 16, 2024

They were indeed silent crashes are these are NOT intended nor should happen. Those were fixed and to mitigate bad usage this extra information should be add to the manual explaining those edge cases:

// array_copy(dest, destIdx, src, srcIdx, length) → Undefined
// 
// Imagine the copy process as the following:
//	* srcIndex - the index where the copy should start (the copy cursor)
//	* abs(length) - is the amount to copy (the amount the cursor will move) 
//	* sign(length) - is the copy direction (the direction in which the cursor moves)
// 
// NOTES (regarding length):
//	* length always includes the srcIndex (if length != 0, the element at this index will always be copied)
//	  independently of the direction of the copy.
// 
// NOTES (regarding destIdx):
//	* negative offsets count from the last element this mean [-1] will NOT append to the array but rather replace the last element.
//	* negative offsets can be out-of-range will just become ZERO by default. 
//	* positive offsets can be out-of-range will expand the destination array (with zeros).
//

@YYBartT @gurpreetsinghmatharoo

test project for QA:

how_array_copy_should_work.zip

@github-project-automation github-project-automation bot moved this from In Progress to Done in Team Workload Oct 16, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo added the documentation Improvements or additions to documentation are required by this issue label Oct 17, 2024
@YYBartT YYBartT self-assigned this Oct 21, 2024
@YYDan YYDan changed the title array_copy with src_index out of bounds will silently crash the game In-Game: array_copy() when "src_index" is invalid will silently crash the game, should show an error Oct 24, 2024
YYBartT added a commit to YoYoGames/GameMaker-Manual that referenced this issue Oct 28, 2024
YoYoGames/GameMaker-Bugs#7917

* Added that array_equals() works recursively and doesn't follow references (it compares the values instead)
* Moved all notes under a "Usage Notes" section
* Reworked the code example and added a second one that shows nested arrays and struct elements (reference types, more generally)
YYBartT added a commit to YoYoGames/GameMaker-Manual that referenced this issue Oct 28, 2024
… crash the game, should show an error

YoYoGames/GameMaker-Bugs#7917

* Updated array_copy page:
  * Added notes on the limitations on source and destination offsets (and ranges) and on inserted zeroes
  * Added a third code example "Extending the Destination Array"
* Added link IDs to the headers on the Arrays page
@YYBartT
Copy link

YYBartT commented Oct 28, 2024

Clarified the limitations on the source and destination array ranges on the array_copy() manual page and added a third code example. Also updated array_equals().

@cameron-home
Copy link

@DiasFranciscoA So what was the fix? Do we have error messages returned when the user does this edgecase instead of a silent crash? Not sure what I'm expecting to see when I check your QA project + the original one.

@DiasFranciscoA
Copy link

DiasFranciscoA commented Nov 11, 2024

there shouldn't be silent crashes... the edge case that the user explains if he is reading out of bounds won't produce an error since values will always be clampped to the available size... if writing out of bounds this is acceptable and the array will expand in size to accomodate the values... the other silent crashing situations have been fixed.
In general the array_copy function was silent crashing if arrays were read and write out of bounds which was incorrect, whatever the user does nothing should trigger a silent crash.

@cameron-home cameron-home moved this from Ready for QA to Todo in Team Workload Nov 11, 2024
@cameron-home
Copy link

Reopening due to this failure in IDE v2024.1100.0.680 Runtime v2024.1100.0.702:Image

@DiasFranciscoA DiasFranciscoA moved this from Todo to Done in Team Workload Nov 11, 2024
@DiasFranciscoA
Copy link

This is now fixed in the Nov24 branch with PR:
https://github.com/YoYoGames/GMS2-Runner-Main/pull/242

@YYBartT YYBartT moved this from Done to Ready for QA in Team Workload Nov 11, 2024
@cameron-home
Copy link

Verified fixed in IDE v2024.1100.0.683 Runtime v2024.1100.0.705, as no more crashes are occurring

@cameron-home cameron-home moved this from Ready for QA to Verified in Team Workload Nov 13, 2024
YYBartT added a commit to YoYoGames/GameMaker-Manual that referenced this issue Nov 19, 2024
…lete() negative offset & length

YoYoGames/GameMaker-Bugs#7917
YoYoGames/GameMaker-Bugs#2785

* Added an item under "offset" on the Array Functions page to indicate it is clamped
* Documented negative index and count for string_delete(), which was missing there (original ticket linked above)
@YYBartT
Copy link

YYBartT commented Nov 19, 2024

Added a note about offset on the Array Functions page to mention reads on the source array cannot go out of bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation are required by this issue project This issue has a sample project attached runner-bug In-game bugs with the "GameMaker Studio 2" runtimes
Projects
Status: Verified
Development

No branches or pull requests

5 participants