GMS 2 Why Does the first ds_map created have the index 2?

Discussion in 'Programming' started by 31Nf4ChZ4H73N, Jan 9, 2020.

  1. 31Nf4ChZ4H73N

    31Nf4ChZ4H73N Member

    Joined:
    Jul 6, 2016
    Posts:
    24
    I stumbled across this weird thing:
    I only have one object oData
    in the create event I create a ds_map nothing more
    Code:
    map = ds_map_create();
    
    now when I open the debuggin tool it tells me that there is one object oData which has a ds_map with the index 2
    [​IMG]
    so when I restart the game by pressing the space bar
    Code:
    ds_map_destroy(map);
    game_restart();
    [​IMG]
    the index of the ds_map is suddenly 0 as it should be. right? why are there two mysterious ds_maps? am I missinterpreting something?

    [EDIT] any idea why the images are not shown?
     
  2. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    204
    You shouldn't rely on IDs outside of runtime. Meaning, in your code you shouldnt be calling an object by it's specific Id, only ever by a variable referencing the object after it's created, if that makes sense. You can't rely on objects having a constant Id so keep that in mind.
     
  3. 31Nf4ChZ4H73N

    31Nf4ChZ4H73N Member

    Joined:
    Jul 6, 2016
    Posts:
    24
    Yes, I know. But I use these IDs at the beginning to make shure that I do not create a memory leak.
    Yesterday I spent almost an hour looking for the memory leak because of this weird starting index until I found it there is none.
     
    kupo15 likes this.
  4. kupo15

    kupo15 Member

    Joined:
    Jun 20, 2016
    Posts:
    881
    Did you also create other ds_types before this one? It would make sense that each DS has its own numbering system but I'm pretty sure they all share the same indexing? I could definitely be totally wrong. I remember debugging an issue where it said "error with grid 10" or something like that and I definitely have more than just grids. I'm pretty sure I didn't have 10 grids though and when I counted through all the ds_creates it lined up. I'm fuzzy on the details with this but give that a check
     
  5. 31Nf4ChZ4H73N

    31Nf4ChZ4H73N Member

    Joined:
    Jul 6, 2016
    Posts:
    24
    No, I created only a whole new project to make shure there are no other DS. and then I only created one ds_map. which was the only thing which happened in the project still got an index of 2 at the beginning.
     
  6. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,822
    Data structures do have separate IDs per type, much to the dismay of anyone who has ever accidentally used list functions when they intended to use grid functions, or any other combination of data structure types.



    @31Nf4ChZ4H73N (thank Theoxidos for @mention autocomplete!):
    The ID of the first map I create in my test project is 0... outside of debug mode. If I start it in debug mode, it's 2.

    The other two maps are probably internally-created ones used to store debug information.
     
    kupo15 and IndianaBones like this.
  7. kupo15

    kupo15 Member

    Joined:
    Jun 20, 2016
    Posts:
    881
    I didn't think I was correct haha yours makes complete sense! =)
     

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