[Solved] Intermittent crashing when a room loads, grid index / bounds error.

Discussion in 'Programming' started by Carcophan, Jan 14, 2020 at 2:45 PM.

  1. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    112
    Hello everyone!

    I am experiencing intermittent crashing issues when loading my game/play rooms.

    I am overly confused why this is a 'sometimes' issue and not an 'all the time' issue.

    The problem seems to focus on a now famous 'Grid 0, index out of bounds writing [24,20] - size is [24,24]' error.

    The room will just crash/hang up/freeze and you have to alt+ctrl+del to close out of GMS. I have gone down the -1 path, changing the size of the grid, compared to the variable size, etc. But that doesn't explain why it only happens sometimes and not always.


    /code]randomize();
    surface = noone;
    global.tileSize = 64;
    global.mazeWidth = 24;
    global.mazeHeight = 24;

    global.grid1 = ds_grid_create(global.mazeWidth , global.mazeHeight);
    ds_grid_clear(global.grid1, 0);
    show_message(string(ds_grid_width(global.grid1)))
    show_message(string(ds_grid_height(global.grid1)))
    ............stuff here [/code]

    If there were an issue, shouldn't it happen all the time and the game fails to load?

    This is hard to debug due to the ALT-CTRL-DEL requirement of the crashing. Using messages as break stops work as expected, unless the game crashes and 'error message 1' will not even load because the entire game just freezes.
     
  2. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    1,063
    Is ds_grid_clear really the only place where the grid is written to? Looks like there is an argument somewhere that is 24, when it should be in the range 0-23.
     
  3. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    112
    I should add, that the grid0 error message only comes up sometimes in the crashes too. Most of the time, it just crashes with no errors or anything.

    The grid0 error may or may not be related to the intermittent crashing - is there anything memory-wise or something outside of that that causes this behavior?

    I HAVE found another instance of grid being used and it being out of bounds, but this too does not make sense because it is triggered on an object collision, which never actually occurs before the crash issue.


    Results in an output of: inner undefined -- 38 AND 15

    Where the 'undefined' is the value of the grid1 array. The ranLocXX is out of bounds here, but this is the section that never even gets called.

    I understand that I have a lot of work to do still, but this is growing more confusing. I am just 'missing' something from my understanding of this, despite reading and rereading content. Even posting other questions and answers about the topic in the past and I am still not there.
     
  4. Xer0botXer0

    Xer0botXer0 Member

    Joined:
    Jun 29, 2016
    Posts:
    675
    Have you run this through the debugger ? Step for step ?
     
  5. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    1,063
    Your definition of the grid size is not consistent with how your use div to pick a grid element. If you want it to be a dynamic size, create the grid with room width and height div how many pixels you want a grid element to cover. If you want a static size of the grid, just use the defined width and height of the grid as the max values for picking a grid element. Currently, using room dimensions div 24 could yield numbers larger than the currently allocated grid dimensions.
     
  6. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    112
    I've rebooted the PC, cleared Cache and Cookies, and restarted the modem too.

    Kidding, But seriously - I am trying to do that, but it is hard. You can run the game 'fine' 49 times, but that 50th time it will crash. Sitting through a trillion F5's hoping the 'next one is the one'. I haven't caught it that way yet.


    Besides, it does not address the intermittent nature of the issue. Why does it work 49 times. Other times it crashes 10 times in a row.
     
  7. Nidoking

    Nidoking Member

    Joined:
    Nov 20, 2019
    Posts:
    16
    You're using a random function, irandom_range. That's literally what random functions do - they produce a different result every time. Your grid has 24 rows and 24 columns. They are number 0 through 23 in each dimension. If you attempt to access row 24 or higher, or column 24 or higher, it will crash with the error you've posted, which says that you tried to access row 24 of a grid with 24 rows, which are numbered 0 through 23.

    You're dividing the room width and height by the size of the grid. As chamaeleon said, that can result in numbers greater than 23. For example, if your room width is 1200, then room_width div 24 is 50. Subtract three and you're left with 47. If your random number between 3 and 47 is greater than 23, you get that error. If it's smaller, you don't get the error. You probably want mod rather than div, which will always give you a number less than 24, but I have no idea what that line is meant to accomplish. Suffice it to say, that is guaranteed to be your problem.
     
    chamaeleon likes this.
  8. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    112
    Wow, thanks for this wording/perspective. I wasn't trying to ignore anyone's input, I just didn't really understand that was 'how it worked'.

    You all rock!

    Edit:
    Also, tired-eyes or something, because I read, reread and read again... and could NOT see that it said room_size there instead of the other locations which have: ranLocXX = irandom_range((global.mazeWidth div 2),global.mazeWidth - 3);
     
    Last edited: Jan 15, 2020 at 4:58 AM

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice