Error: Memory allocation failed

C

Chris Livermore

Guest
Hi guys,

im using GMS 2 on a windows 10 Machine.

im getting the below error when automating tile drawing to my background layer of a room and Im not sure why as I would have thought the code does not produce that much memory usage!? I am using a 20000x20000 room though so maybe that why? It worked on a 5000x5000 room when I tested origionally....

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object objTileSetter:

Memory allocation failed: Attempting to allocate 2500000000 bytes
at gml_Object_objTileSetter_Create_0 (line 4) - global.background_Tilemap_Space = layer_tilemap_create(global.background_Layer,0,0,tsSpace,room_width,room_height);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_objTileSetter_Create_0 (line 4)


the problem code is this:



global.background_Layer = "Background";
global.background_Tilemap_Space = layer_tilemap_create(global.background_Layer,0,0,tsSpace,room_width,room_height);


/// @description Automatically draw background.

var tileWidth,tileHeight;
tileWidth = 64; // tile width
tileHeight = 64; // tile height
var Down, Across;
Across = room_width / tileWidth; // number of time to go accross
Down = room_height /tileHeight; // number of time to go down


for (var a =1; a < Down; a++;){ // simple for loop to go down the room
for(var i =1; i < Across; i++;){ // simple for loop to go accross the room
var ran_data = irandom_range(1,100);
tilemap_set_at_pixel(global.background_Tilemap_Space,ran_data,((tileWidth/2)+1)*i,((tileHeight/2)+1)*a)
}
}
 

Dupletor

Member
Don't try to allocate 2.5gb at once.
You can make the OS accept it, but I don't think you have to. And you would need a loading screen.
 
C

Chris Livermore

Guest
do you think it would be better to draw it line by line instead of for within a for?
 

Dupletor

Member
I don't know the context, if you have a room this big you probably don't need it loaded on its entirety.
 
C

Chris Livermore

Guest
good point, I will look into fixing this one. thanks for your help.
 
Top