GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2008-03-07 15:01:27

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

ds_grid_set_grid_region - confirmed BUG in GM7

This new GM7 function:

ds_grid_set_grid_region(id,source,x1,y1,x2,y2,xpos,ypos) Copies the contents of the cells in the region in grid source to grid id. xpos and ypos indicate the place where the region must be placed in the grid. (Can also be used to copy values from one place in a grid to another.)

... is broken.

xot @ GMC wrote:

What I've found is that with each successive call, the area that can be addressed "shortens" by one. That is, on the first call, you have full access, on the next call, you can't access the last row, on the following call, you can't access the bottom two rows, and on the next, the last three rows are inaccessible, and so on. This bug was driving up the wall until I realized that the problem wasn't in my code, but with GM. I replaced the function with a script, and my code worked fine. It is definitely a Game Maker BUG.

http://gmc.yoyogames.com/index.php?showtopic=338408


xot @ GMC wrote:

The work around is to replace ds_grid_set_grid_region() with your own version. You can even keep it the same name and your script will be used instead of the built-in function. That's a useful feature that simplifies code updates when the bug is finally fixed; you only need to remove your replacement and everything that uses ds_grid_set_grid_region() will be updated automagically.


// ds_grid_set_grid_region(dst,src,x1,y1,x2,y2,xpos,ypos)
// NOTE: This is a replacement for the buggy GM7 function of the same name.
var xoff,yoff,i,j;
xoff = argument6-argument2;
yoff = argument7-argument3;
for (i=argument2; i<=argument4; i+=1) {
    for (j=argument3; j<=argument5; j+=1) {
        ds_grid_set(argument0,i+xoff,j+yoff,ds_grid_get(argument1,i,j));
    }
}

http://gmc.yoyogames.com/index.php?showtopic=363209


Abusing forum power since 1986.

Offline

#2 2008-03-29 19:51:37

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: ds_grid_set_grid_region - confirmed BUG in GM7

I noticed a problem with that replacement script today. If the source and destination are the same (which is normally allowed), then the data may not be copied correctly if the regions overlap. Below is a smarter version that corrects that oversight. It could be faster by using ds_grid_copy() instead of manually copying each cell, but by doing it this way the function also works for GM6 users.

http://www.gmlscripts.com/script/ds_gri … rid_region

/*
**  Usage:
**      ds_grid_set_grid_region(id,source,x1,y1,x2,y2,xpos,ypos)
**
**  Arguments:
**      id          destination ds_grid to copy values to
**      source      source ds_grid to copy values from
**      x1,y1       upper-left corner of the region to be copied
**      x2,y2       lower-right corner of the region to be copied
**      xpos,ypos   position in the destination to copy values to
**
**  Returns:
**      nothing
**
**  Notes:
**      This function replaces the buggy Game Maker 7 version of the
**      same name. It also adds the same functionality to Game Maker 6.
**
**  GMLscripts.com
*/
{
    var copy,xoff,yoff,i,j;
    if (argument0 != argument1) copy = -1;
    else {
        copy = ds_grid_create(argument4+1,argument5+1);
        for (i=argument2; i<=argument4; i+=1) {
            for (j=argument3; j<=argument5; j+=1) {
                ds_grid_set(copy,i,j,ds_grid_get(argument1,i,j));
            }
        }
        argument1 = copy;
    }
    xoff = argument6-argument2;
    yoff = argument7-argument3;
    for (i=argument2; i<=argument4; i+=1) {
        for (j=argument3; j<=argument5; j+=1) {
            ds_grid_set(argument0,i+xoff,j+yoff,ds_grid_get(argument1,i,j));
        }
    }
    if (copy != -1) ds_grid_destroy(copy);
}

Abusing forum power since 1986.

Offline

#3 2009-05-17 20:14:01

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: ds_grid_set_grid_region - confirmed BUG in GM7

Brief Description:            ds_grid_*_grid_region - this set of functions has data area reading bugs
GM Versions:                   GM7
References:                     [1] [2]
Example File:                   ds_grid grid region bug.gmk
Bug Confirmed:                Yes
Hardware Dependent:     No

Main Info:

This bug exists in the functions ds_grid_set_grid_region, ds_grid_add_grid_region and ds_grid_multiply_grid_region. It causes the data error that should be set to be incorrect. I advise looking at the example file provided to see this problem more clearly.

- If you press the (1) key to set it into bug position 1 you can see that the last 2 columns and rows are not set event though they are in the data area to be set. It appears that the width of the data is incorrectly being set to the Main Grid width instead of the Grid To Set From.

- If you press the (2) key to set it into bug position 2 you can see that the last column is not set even though it is in the data area to be set. This is caused by y position of the Grid To Set From, if you move y1 to the top (left click twice) you will see it then sets correctly. You will also see if you move the ypos up (by left clicking) the 2nd to bottom row is also affect, however the 3rd to bottom is not. The amount of rows from the bottom that is bugged is equal to the amount of rows that y1 is set down. I don't know exactly what GM is doing to cause this bug but I can only presume it is caused by the same bug with the width/height being incorrectly set from the main grid instead.

Workaround:

Check gmlscripts for alternative functions which you can use as replacements.

Last edited by flexaplex (2009-07-07 18:58:09)

Offline

#4 2009-07-06 10:08:45

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: ds_grid_set_grid_region - confirmed BUG in GM7

Edit: Never mind I have it now.

Last edited by flexaplex (2009-07-07 18:58:41)

Offline

#5 2009-07-07 19:01:06

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: ds_grid_set_grid_region - confirmed BUG in GM7

OK I have finally updated this and provided an example file thanks to icuurd who made me realise what the bug actually was.

Icuurd also noticed that this bug exists in the add and multiply functions not just the set. So if you want a proper workaround for this to be available those two functions will have to be manually rewritten also.

Offline

Board footer

Powered by FluxBB