3D Memory leaks when using 3D buffers

BlueHarrier

Member
I'm working on a 2.5D platformer game and using 3D planes instead of sprites. The problem comes when preparing the buffer for drawing. I don't know why the memory keeps increasing if I'm theorically deleting the buffer after drawing the sprite.

For drawing every layer, I'm using layer managers and a queue system for storing every object:

Code:
while (!ds_queue_empty(queue))
{
    with (ds_queue_dequeue(queue))
    {

        var draw_x, draw_y;

        draw_x[0]=x-lengthdir_x(sprite_xoffset, image_angle)+lengthdir_y(sprite_yoffset, image_angle)
        draw_y[0]=y-lengthdir_x(sprite_yoffset, image_angle)-lengthdir_y(sprite_xoffset, image_angle)
        draw_x[1]=x-lengthdir_x(sprite_xoffset, image_angle)-lengthdir_y(sprite_height-sprite_yoffset, image_angle)
        draw_y[1]=y+lengthdir_x(sprite_height-sprite_yoffset, image_angle)-lengthdir_y(sprite_xoffset, image_angle)
        draw_x[2]=x+lengthdir_x(sprite_width-sprite_xoffset, image_angle)+lengthdir_y(sprite_yoffset, image_angle)
        draw_y[2]=y-lengthdir_x(sprite_yoffset, image_angle)+lengthdir_y(sprite_width-sprite_xoffset, image_angle)
        draw_x[3]=x+lengthdir_x(sprite_width-sprite_xoffset, image_angle)-lengthdir_y(sprite_height-sprite_yoffset, image_angle)
        draw_y[3]=y+lengthdir_x(sprite_height-sprite_yoffset, image_angle)+lengthdir_y(sprite_width-sprite_xoffset, image_angle)

        var
        tex=sprite_get_texture(sprite_index, image_index),
        uvs=texture_get_uvs(tex);

        vertex_format_begin()

        vertex_format_add_position_3d()
        vertex_format_add_color()
        vertex_format_add_texcoord()

        var format=vertex_format_end();

        var plane_model=vertex_create_buffer();

        vertex_begin(plane_model, format)

        //Triangle 1

        vertex_position_3d(plane_model, draw_x[0], draw_y[0], other.z)
        vertex_color(plane_model, image_blend, image_alpha)
        vertex_texcoord(plane_model, uvs[0], uvs[1])

        vertex_position_3d(plane_model, draw_x[1], draw_y[1], other.z)
        vertex_color(plane_model, image_blend, image_alpha)
        vertex_texcoord(plane_model, uvs[0], uvs[3])

        vertex_position_3d(plane_model, draw_x[2], draw_y[2], other.z)
        vertex_color(plane_model, image_blend, image_alpha)
        vertex_texcoord(plane_model, uvs[2], uvs[1])

        //Triangle 2

        vertex_position_3d(plane_model, draw_x[2], draw_y[2], other.z)
        vertex_color(plane_model, image_blend, image_alpha)
        vertex_texcoord(plane_model, uvs[2], uvs[1])

        vertex_position_3d(plane_model, draw_x[1], draw_y[1], other.z)
        vertex_color(plane_model, image_blend, image_alpha)
        vertex_texcoord(plane_model, uvs[0], uvs[3])

        vertex_position_3d(plane_model, draw_x[3], draw_y[3], other.z)
        vertex_color(plane_model, image_blend, image_alpha)
        vertex_texcoord(plane_model, uvs[2], uvs[3])

        vertex_end(plane_model)

        vertex_submit(plane_model, pr_trianglelist, tex)

        vertex_delete_buffer(plane_model)

        vertex_format_delete(format)
    }
}
 

Attachments

Are you sure this is what causing thr leak? the code looks fine. but you should only create the format and the buffer once at the beginning of the game/level then using matrices to transform the buffer.
 

BlueHarrier

Member
Are you sure this is what causing thr leak? the code looks fine. but you should only create the format and the buffer once at the beginning of the game/level then using matrices to transform the buffer.
That was my plan B, but I don't know how to modify the UVSs of the textures.
 
Top