• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Understanding the error 'Invalid surface dimensions'

MeltingCat

Member
I have gotten this error 'Invalid surface dimensions' after using surface_resize in a room start event.
The error occurs only sometimes - I can't quite figure out a pattern behind it and would like to know more what invalid surface dimensions might be.

A google search brings nothing but one thread on reddit, where nobody provides a helpful response, apart from rounding the pixels to integers, which I am doing.
The error occurs sometimes when the game might not know what room to enter after trying to load a save file which doesn't exist - but I tried to get around this and it still comes up every so often. Here is my code of my camera object in the room start event - I'm using this to change the camera dimensions according to the screen size.

Code:
Width = camera_get_view_width(view_camera[0]);
Height = camera_get_view_height(view_camera[0]);

var _CamAspect = Width/Height;

DispW = display_get_width();
DispH = display_get_height();
var _DispAspect = DispW / DispH;

if _CamAspect != _DispAspect {
  
    Height = Width / _DispAspect;
    var _Wport = view_get_wport(view_camera[0]);
    var _Hport = _Wport / _DispAspect;
    view_set_hport(0, round(_Hport));
    view_hport[0] = _Hport;

}

camera_set_view_size(view_camera[0], round(Width), round(Height));

SurfW = round(Width);
SurfH = round(Height);

surface_resize(application_surface, SurfW, SurfH);
Thank you for any help provided. Any information regarding surface dimensions is helpful.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Invalid surface dimensions usually means that one or the other (width/height) is being set to 0... so you'll want to check the values for the SurfW/SurfH variables. Do you destroy the view cameras at any time? If the view camera you are using to get the width/height values has been destroyed, then that might cause the width/height values to be 0, and so give you the error.
 

MeltingCat

Member
Thank you for your answer. I'm not destroying the camera purposefully at any point, but the error might mean a room without a view camera being present maybe... That seems to be the only thing I can think of so far.
 

NightFrost

Member
Every room has a default camera when it is created so you should be able to access its values. Even if no views are active, the default camera exists.
 

Nidoking

Member
For a bit more insight, add some debug statements. show_debug_message string(Width) and string(Height) before calling the function, and you'll see what invalid dimensions look like. Then work backward from there to figure out where they're coming from.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Every room has a default camera when it is created so you should be able to access its values. Even if no views are active, the default camera exists.
Yup... However, while every room does have a default camera, if there are no views active, then view_camera[n] will not hold a camera ID - which they are accessing - and so they'd need to use the camera_get_default() function instead.
 

NightFrost

Member
Yup... However, while every room does have a default camera, if there are no views active, then view_camera[n] will not hold a camera ID - which they are accessing - and so they'd need to use the camera_get_default() function instead.
I see; I remember testing this once and discovering view_camera[0] was available even with no view. This was in the middle of a project however and it may well be a view was in fact on by the time my test ran.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I see; I remember testing this once and discovering view_camera[0] was available even with no view. This was in the middle of a project however and it may well be a view was in fact on by the time my test ran.
Hmmmm.... I may be wrong too!!! I'd need to test and see...
 

MeltingCat

Member
Thank you for all replies. I added some debug messages and found out that camera_get_view_width(view_camera[0]) was set to "-1", which I presume means that the camera didn't exist. It occured when my "Load_Game" script was going to an unknown room. I solved it by making sure that it won't leave the room unless the game knows where to go ;)
 
Top