HTML5 html5 freeze bug

Discussion in 'GameMaker Studio 2 Community Tech Support' started by splendidtank, May 30, 2018.

  1. splendidtank

    splendidtank Member

    Joined:
    Feb 19, 2017
    Posts:
    9
    HEY!

    having a bug atm... when i launch the game in html5 format it works fine with the menu aswell as the cutsceene but, when the first level starts, the image freezes... the game still works tho, i know that because of the sounds. this does that i cant upload games to for example kongregate :( this video example is from kongregate but it happens inside gamemaker studio 2 too... really bugging me...




     
  2. chmod777

    chmod777 Member

    Joined:
    Aug 26, 2016
    Posts:
    202
    So if you disable the sounds, the game no longer freezes? Have you got any issue reported in the browser's console (better to check in debug mode)?
     
  3. splendidtank

    splendidtank Member

    Joined:
    Feb 19, 2017
    Posts:
    9
    no, it still freezes... what i meant is that it is just the image that is frozen. the game works fine and i can hear that becouse of the sounds. no issue in browser console... gonna try debug mode :)
     
  4. splendidtank

    splendidtank Member

    Joined:
    Feb 19, 2017
    Posts:
    9
    found out it was the camera! do anyone see anything wrong here? (Works fine when runned on windows)

    /// @description update camera

    //update destination
    if (instance_exists(follow))
    {
    xTo = follow.x;
    yTo = follow.y;

    if ((follow).object_index == oPdead)
    {
    x = xTo;
    y = yTo;
    }
    }

    //Update object position
    x += (xTo - x) / 25;
    y += (yTo - y) / 25;


    x = clamp(x,view_w_half+buff,room_width-view_w_half-buff);
    y = clamp(y,view_h_half+buff,room_height-view_h_half-buff);
    //screen shake
    x += random_range(-shake_remain,shake_remain);
    y += random_range(-shake_remain,shake_remain);
    shake_remain = max(0,shake_remain-((1/shake_length)*shake_magnitude));

    // update camera view
    camera_set_view_pos(cam,x-view_w_half,y-view_h_half);
    if (layer_exists("Mountains"))
    {
    layer_x("Mountains",x/2);
    }
     
  5. splendidtank

    splendidtank Member

    Joined:
    Feb 19, 2017
    Posts:
    9
    after som more digging i found out that the line under "//update camera view" is the issue
    Code:
    camera_set_view_pos(cam,x-view_w_half,y-view_h_half); 
    
     
  6. splendidtank

    splendidtank Member

    Joined:
    Feb 19, 2017
    Posts:
    9
    but i dont know how to solve it
     
  7. MarceloP

    MarceloP Member

    Joined:
    Apr 11, 2018
    Posts:
    254
    Are you sure that your "cam" variable has the correct id of a camera on HTML5? When and How are you getting the camera on your "cam" variable?

    Another thing, your line:
    Code:
    //Update object position
    x += (xTo - x) / 25;
    y += (yTo - y) / 25;
    is outside your "if (instance_exists(follow))", is that right? I mean, x and y should be updated by xTo and yTo even though follow doesn't exists?

    Try checking the existence and the ID of the camera before trying to change it, sometimes in HTML5 things that are "miscoded" are shown more easily. I also think this should be in the programming section of the forum, not on the Tech Support, unless this is a bug, which doesn't seems to be xD
     
  8. Gunnar the Clovis

    Gunnar the Clovis Member

    Joined:
    Apr 4, 2018
    Posts:
    4
    Hi splendidtank and any future readers with this same problem:

    I had the exact same issue, and have identified the solution. I made a thread detailing my own experience, research, and experimentation on this problem, which can be found here: https://forum.yoyogames.com/index.p...w_pos-silently-freezes-on-html5-target.66494/

    The problem lies with the screenshake code:
    Code:
    //screen shake
    x += random_range(-shake_remain,shake_remain);
    y += random_range(-shake_remain,shake_remain);
    shake_remain = max(0,shake_remain-((1/shake_length)*shake_magnitude));
    When shake_remain is 0 (as it always is when no screenshake is being applied), this code adds random_range(-0, 0) to x & y. This is completely fine on all platforms... except HTML5. While on all other platforms this simply adds 0 to the x & y values, changing nothing and having no effect, for whatever reason HTML5 & JavaScript are unable to process this math. When -0 or whatever other funky math identifier JavsScript is using is added to the x & y values, and then these values are used in camera_view_set_pos in any way, the HTML5 app freaks out, freezes, and crashes. By simply wrapping the screenshake code in an if-statement, this can be avoided. This is a minor (almost pointlessly minor) optimization on all other platforms, but JavaScript has a history of problems with math, and needs this extra protection.

    Fixed version:
    Code:
    if(shake_remain > 0)
    {
       // Screen shake
       x += random_range(-shake_remain, shake_remain);
       y += random_range(-shake_remain, shake_remain);
       shake_remain = max(0, shake_remain - shake_magnitude / shake_length);
    }
    
    camera_set_view_pos(cam, x - view_w_half, y - view_h_half);
    While this is a fixable and avoidable problem, it certainly isn't expected or desired behavior, so hopefully this math problem will be fixed in the future.
     

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