1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Windows [Closed, bug reported] Game crashes on sprite_add_from_surface

Discussion in 'Programming' started by Wraithious, Oct 20, 2017.

Tags:
  1. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    Hello, In my game I have an alarm event that makes a surface and draws stuff, then adds a sub image to a sprite from the surface, but it crashes the game hard (like crashes windows, no error message reported from game maker) so I ran it in the debugger and it crashes at the first call to sprite_add_from_surface. All other variables up to that point all have the correct/expected values, and I have added the sprites in the resource tree like normal, they are not imported from a file. Here is my alarm code:
    Code:
    ///Captain's log stardate 20171018 - Make pages
    num=sprite_get_number(spr_content);
    num2=sprite_get_number(invertNo);
    num3=sprite_get_number(invertYes);
    spr=sprite_create_from_surface(application_surface,0,0,736,414,0,0,0,0);
    
    sur=surface_create(394,294);
    surface_set_target(sur);
    draw_clear_alpha(-1,0);
    if(sprite_exists(spr))
    {global.maxpage+=1;
    draw_sprite_ext(spr,0,0,0,0.535,0.71,0,-1,1);
    draw_set_color(c_white);
    draw_text(191,278,"("+string(global.maxpage)+")");
    surface_reset_target();
    sprite_add_from_surface(spr_content, sur, 0, 0, 394, 294, 0, 0);  //CRASHES windows here
    sprite_add_from_surface(invertNo, sur, 0, 0, 197, 294, 0, 0);
    sprite_add_from_surface(invertNo, sur, 197, 0, 197, 294, 0, 0);
    surface_free(sur);
    
    sur=surface_create(394,294);
    surface_set_target(sur);
    draw_clear_alpha(-1,0);
    draw_sprite_ext(spr,0,0,0,0.535*-1,0.71,0,-1,1);
    surface_reset_target();
    sprite_add_from_surface(invertYes, sur, 197, 0, 197, 294, 0, 0);
    sprite_add_from_surface(invertYes, sur, 0, 0, 197, 294, 0, 0);
    surface_free(sur);
    
    sprite_save_strip(spr_content, "spr_content.png");
    sprite_save_strip(invertNo, "invertNo.png");
    sprite_save_strip(invertYes, "invertYes.png");
    }
    Does anyone know what I might be doing wrong?
     
    Last edited: Oct 22, 2017
  2. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    Wow, so I commented everything out completely and put this in the alarm event:
    Code:
    sprite_add_from_surface(spr_content, application_surface, 0, 0, 394, 294, 0, 0);
    and it crashes the game in the same way, before I file a bug report can anyone please confirm this?
    I tried it this way too to make sure, same problem:
    Code:
    if(surface_exists(application_surface))
    {
    sprite_add_from_surface(spr_content, application_surface, 0, 0, 394, 294, 0, 0);
    }
     
  3. Seabass (The Human)

    Seabass (The Human) Member

    Joined:
    Jun 20, 2016
    Posts:
    357
    Your crash is the result of adding a sprite from a surface you are currently still targeting. At least that's what I can tell from your code. sprite_add_from_surface() has worked fine for the past few years.
     
  4. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    No, I reset the target before calling sprite_add_from_surface
    Code:
    surface_reset_target();
    sprite_add_from_surface(invertYes, sur, 197, 0, 197, 294, 0, 0);
    sprite_add_from_surface(invertYes, sur, 0, 0, 197, 294, 0, 0);
    surface_free(sur);
    
    And then, as I showed, I tried it all by itself with no other code, still crashes.
     
  5. Seabass (The Human)

    Seabass (The Human) Member

    Joined:
    Jun 20, 2016
    Posts:
    357
    What version of Game Maker are you using? Also is the surface smaller than your max texture page size?
     
  6. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    @Seabass (The Human) Im using early access 1.99.551, and my texture pages are set to 2048x2048, in the first test (original) the surface created was 1472x294, so that one was smaller, the second test I used the application surface which should be 736x414, at least that's my room size and background size, so that is also smaller than my texture page size.
     
  7. Seabass (The Human)

    Seabass (The Human) Member

    Joined:
    Jun 20, 2016
    Posts:
    357
    Hmm, perhaps they really did break sprite_add_from_surface(). That just seems really odd because they didn't touch the function for GMS 2.
     
    Wraithious likes this.

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