What is wrong with my code (GUI is drawn improperly after adding different screens support)


Hello everybody. Actually I am having troubles implementing aspect ratio managment stuff as always. I used Pixelated Pope's tutorial for old version of GMS, but I have spoilt somthing trying to implement it in my game (GMS 2). So, at first I was using GMS default stuff: Set the viewport and camera sizes in the room editor, then turned on the keep aspect ratio setting and got what I've expected: black bars on the most of the screens. But then I've decided to change it, and after a few messages on discord I have understood that I have to do it myself and there will be no gifts from the sky:) And damn, I have done it, the resolution works perfectly, I have set up teh maximum and minimum digits for the view and got the pixel perfect image with black bars on ultra wide or ultra high screens, like Pope supposed to do actually. But I still stuck with 1 problem: my GUI is working improperly: the things that have draw coordinates without global.GUI_W or GUI_H variables(left top elements) are drawn properly, but the menu which is anchored to teh bottom right corner:

menu_x = global.GUI_W - 20 - string_width(menu[0]);
menu_y = global.GUI_H - unit_height * unit_count - 20 - units_gap*(unit_count-1);
Is just invisible, and I have even tried setting the menu_x and menu_y to GUI_W /2 and GUI_H /2, but they are still invisible. Also the problem with GUI appears in the other important place:
I have an object controlling my day and time cycle using appropriate shader and drawing application surface manually, and this stuff worked just fine until I have started implementing the changes with aspect ratio. This object actually enables automatic application_surface drawing and in the DRAW_GUI event runs this code:

And finally, this is the aspect ratio managment code in the obj_camera CREATE event:

cam = view_camera[0];

#region//Aspect Ratio Managment

view_visible[0] = true;
view_enabled = true;

var view_w = 960;
var view_h = 540;

var max_view_h = 720;
var max_view_w = 1280;

var min_view_w = 684;
var min_view_h = 384;

//var display_w = display_get_width();
//var display_h = display_get_height()
var display_w = 1120
var display_h = 900
var aspect_ratio = display_w / display_h;

alarm[0] = 1;

view_h = view_w / aspect_ratio;

if(view_w mod display_w !=0)
    var scale = display_w div view_w;
    var expanded_width = display_w / scale;
    var cropped_width = display_w / (scale + 1)
    if((expanded_width - view_w) <= (view_w - cropped_width)) view_w = expanded_width;
    else view_w = cropped_width;

if(view_h mod display_h !=0)
    var scale = display_h div view_h;
    var expanded_height = display_h / scale;
    var cropped_height = display_h / (scale + 1)
    if((expanded_height - view_h) < (view_h - cropped_height)) view_h = expanded_height;
        view_h = cropped_height;

view_w += view_w mod 2;
view_h += view_h mod 2;

view_w = clamp(view_w,min_view_w,max_view_w)
view_h = clamp(view_h,min_view_h,max_view_h)

surface_resize(application_surface,view_w * scale,view_h * scale);


display_set_gui_size(view_w ,view_h)

global.GUI_W = display_get_gui_width();
global.GUI_H = display_get_gui_height();

Yeah, so I am really happy that now this stuff works fine and I have tested it with some sorts of crazy resolutions, unfortunately up to my 1280 x 1024 and it works really nice, but I am really upset with that GUI problem, so I hope somebody can help me.