1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Android Trying to use non-existing surface.

Discussion in 'Programming' started by RyanC, May 17, 2019 at 3:33 PM.

  1. RyanC

    RyanC Member

    Joined:
    Jun 24, 2016
    Posts:
    358
    Hi All,

    I've been having some trouble with a bug in my game and was wondering if anyone can take a look at this?

    The issue happens with the following two pieces of code:

    on Alarm[0]
    Code:
    if (!surface_exists(pause_surf))
    {
        surf_w = surface_get_width(application_surface);
        surf_h = surface_get_height(application_surface);
        pause_surf = surface_create(surf_w,surf_h);
    }
    
    
    
    if surface_exists(pause_surf) surface_copy(pause_surf,0,0,application_surface);
    
    instance_deactivate_all(true); 
    on Alarm[3]
    Code:
       
    surf_w = surface_get_width(application_surface);
    surf_h = surface_get_height(application_surface);
    pause_surf = surface_create(surf_w,surf_h);
    if surface_exists(pause_surf) surface_copy(pause_surf,0,0,application_surface);
    instance_deactivate_all(true);
    

    Draw Event
    Code:
    if surface_exists(pause_surf)
    {
        draw_surface_ext(pause_surf,view_xview,view_yview,view_wview/surf_w,view_hview/surf_h,0,-1,1);
    
    }
    else
    if ! alarm[1]
    {
    
        instance_activate_all();
    
        alarm[3] = 2
        
        alarm[1] = 10 // prevent possible crashing   
    }
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,788
    When does it crash? Does it crash on PC?

    Here is what I use on Android for a full screen save so I don't have to worry about the surface freeing itself accidentally. It doesn't crash for me, but I've never tested it on more than my own device (or very rigorously even on that):

    Code:
    
    ///create event
    
    //save application surface to a buffer
    var buff = buffer_create(surface_get_width(application_surface) * surface_get_height(application_surface) * 4, buffer_grow, 1);
    buffer_get_surface(buff, application_surface, 0, 0, 0);
    buffer_save(buff, "gameplay_surface.buf");
    
    //delete buffer and surface
    buffer_delete(buff);
    
    
    Code:
    
    ///draw (GUI I think?) event
    
    //load in buffer, create surface, set surface to buffer
    var buff = buffer_load("gameplay_surface.buf");
    var surf = surface_create(surface_get_width(application_surface), surface_get_height(application_surface));
    buffer_set_surface(buff, surf, 0, 0, 0);
    
    //draw surface
    draw_surface(surf, 0, 0);
    
    //destroy buffer and surface
    buffer_delete(buff);
    surface_free(surf);
    
    
     

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