• 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!

Memory issues (GM8)

O

orSQUADstra

Guest
I'm using GameMaker 8.0 for this project.

I've been experimenting on some features, one of which needs to creates a sprite from a 100x50 part of the screen via sprite_add_from_screen(). After that, it draws the sprite, and after being drawn it gets deleted. This repeats every single frame. (I know, it doesn't sound too practical.)

Now, my problem is, I can't see how I could solve one HUGE issue with this - what else am I supposed to do if I don't want the memory usage to rocket up to the sky? How could I free the memory from the previous sprite?

Any help is appreciated!
 
O

orSQUADstra

Guest
Its not supposed to sky rocket. Use the sprite_delete() function.
I do use it. But it still gets to 1 GB of ram in about 30 seconds, and after some more time it completely freezes.

Here's a piece of code for the draw event:
Code:
ownBackBlur = blur_sprite(sprite_create_from_screen(xx,yy-global.titlebarheight,w,h+global.titlebarheight,false,false,0,0))

draw_sprite(ownBackBlur,0,xx,yy-global.titlebarheight)

sprite_delete(ownBackBlur)
And here's the code for the blur_sprite script:

Code:
var blurSurf0, blurSurf1, blurSpr;
blurSurf0 = surface_create(floor(sprite_get_width(argument0)*.5),floor(sprite_get_height(argument0)*.5))
blurSurf1 = surface_create(sprite_get_width(argument0),sprite_get_height(argument0))

texture_set_interpolation(true)

surface_set_target(blurSurf1)
    draw_sprite_stretched(argument0,0,0,0,surface_get_width(blurSurf1),surface_get_height(blurSurf1))
surface_reset_target()

repeat(10)
{
    surface_set_target(blurSurf0)
        draw_surface_stretched(blurSurf1,0,0,surface_get_width(blurSurf0),surface_get_height(blurSurf0))
    surface_reset_target()
    
        surface_set_target(blurSurf1)
        draw_surface_stretched(blurSurf0,0,0,surface_get_width(blurSurf1),surface_get_height(blurSurf1))
    surface_reset_target()
}
texture_set_interpolation(false)

blurSpr = sprite_create_from_surface(blurSurf1,0,0,surface_get_width(blurSurf1),surface_get_height(blurSurf1),false,false,0,0)
return blurSpr

sprite_delete(blurSpr)
surface_free(blurSurf0)
surface_free(blurSurf1)
 
O

orSQUADstra

Guest
Ah, nevermind, just replaced the blur_sprite(sprite_create_from_screen(...)) part with blur_sprite(sprToBlur), and set the sprToBlur variable to sprite_create_from_screen(...), and now it works.

Thanks though!
 
A

anastasialeemartin

Guest
trying to index a variable which is not an array
at gml_Object_obj_scoreforleader_Draw_0 (line 14) - draw_text(x, y, string(global.score_array[i, 0]))

does any1 know the reason for this error?
draw_set_font(f_score);
draw_set_halign(fa_left);
draw_set_valign(fa_center);
draw_set_color(c_black);

x = room_width/2 - 150;
y = 100;

for (i = 0; i<10; i++)
{
y += 50;
draw_text(x, y, string(global.score_array[i, 0]))
draw_text(x + 200,y, string(global.score_array[i, 1]));
}
 
L

Lonewolff

Guest
Do you really need to create a Sprite each frame? That is very slow and expensive. Can't use a surface instead?
 
O

orSQUADstra

Guest
Do you really need to create a Sprite each frame? That is very slow and expensive. Can't use a surface instead?
There isn't a surface_create_from_screen function, so no :/
But anyway, it's not that bad since I'm really only using it for a thin line.
 

DukeSoft

Member
Why don't you draw the sprite on 1 surface at create, then call the blur function on just that surface every time, and only draw that surface?

This will also give a blur out effect but it resides on 1 surface and you don't need to keep creating sprites :)

EDIT:

There is no surface_create_from_screen because the application_surface _is_ your screen (except for the gui layer).

So you can create a surface, copy a part of the application_surface to your surface, and there you go :)
 
O

orSQUADstra

Guest
Why don't you draw the sprite on 1 surface at create, then call the blur function on just that surface every time, and only draw that surface?

This will also give a blur out effect but it resides on 1 surface and you don't need to keep creating sprites :)

EDIT:

There is no surface_create_from_screen because the application_surface _is_ your screen (except for the gui layer).

So you can create a surface, copy a part of the application_surface to your surface, and there you go :)
Again, I'm using GameMaker 8.0. There isn't a GUI layer in there.
 
L

Lonewolff

Guest
Create a surface and draw to it first.

[edit]
Yep, dukesoft is thinking along the same lines.

You don't need a GUI layer to do this.
 
O

orSQUADstra

Guest
Create a surface and draw to it first.

[edit]
Yep, dukesoft is thinking along the same lines.

You don't need a GUI layer to do this.
Yeah, but there are way too many objects to draw them all on a surface. Not to mention that I use alphas a lot of places, and surfaces draw weirdly when an alpha isn't 0 or 1.
 
L

Lonewolff

Guest
Well, that's how I would (and do) dot it.

Anyway, I hope you find a solution :)
 
Top