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

[SOLVED] buffer_get_surface don't copy surface into buffer

T

threadom

Guest
Hi everyone,

i currently implement a 3D chunk system and i encounter a problem with buffer_get_surface.
Surface is not copied into srcBuff.

i have checked suface is correctly created and filed :

upload_2019-8-18_14-43-9.png

upload_2019-8-18_14-47-13.png

In a global_init file :
Code:
global.chunk_size = 512;
global.chunk_surface_bytes = global.chunk_size*2*4;
In a chunk_texture_writer file :
Code:
    surface_reset_target();
    var srcBuff = buffer_create(global.chunk_surface_bytes, buffer_grow, 1);
    buffer_get_surface(srcBuff, surf, buffer_surface_copy, 0, 0);
    var cmpBuff = buffer_compress(srcBuff,0,global.chunk_surface_bytes);
    buffer_save(srcBuff,_room_cur+"_"+string(ii)+".dat");
    surface_free(surf);
this morning everything work, but today i added some global (chunk_size, chunk_surface_bytes), after it that seem broken.
 
T

threadom

Guest
here code, png

Code:
show_debug_message("Texture Writer Start : " + date_time_string(date_current_datetime()));

var _room_cur = argument0
var _xmin = argument1
var _xmax = argument2
var _ymin = argument3
var _ymax = argument4

var ww = _xmax - _xmin;
var hh = _ymax - _ymin;

var tm_1 = layer_tilemap_get_id("texturemap_1");
var tm_2 = layer_tilemap_get_id("texturemap_2");
var tm_3 = layer_tilemap_get_id("texturemap_3");
//var srcBuff;

ii=0;
for (var ii=0;ii<=7;ii++) {
    var surf = surface_create(global.chunk_size, global.chunk_size);
    surface_set_target(surf);
    draw_clear_alpha(c_black, 0);

    for (var yy=_ymin;yy<_ymax;yy++) {
        for (var xx=_xmin;xx<_xmax;xx++) {
            var texture_id = floor(tilemap_get(tm_1,xx,yy));
            //if (texture_id > 0) {
                var ty = floor(texture_id/16);
                var tx = texture_id - (ty*16);
                draw_sprite_part(spr_grassland, ii, tx*64, ty*64, 64, 64, (xx-_xmin)*64, (yy-_ymin)*64);
            //}
        }
    }

    for (var yy=_ymin;yy<_ymax;yy++) {
        for (var xx=_xmin;xx<_xmax;xx++) {
            var texture_id = floor(tilemap_get(tm_2,xx,yy));
            if (texture_id > 0) {
                var ty = floor(texture_id/16);
                var tx = texture_id - (ty*16);
                draw_sprite_part(spr_grassland, ii, tx*64, ty*64, 64, 64, (xx-_xmin)*64, (yy-_ymin)*64);
            }
        }
    }

    for (var yy=_ymin;yy<_ymax;yy++) {
        for (var xx=_xmin;xx<_xmax;xx++) {
            var texture_id = floor(tilemap_get(tm_3,xx,yy));
            if (texture_id > 0) {
                var ty = floor(texture_id/16);
                var tx = texture_id - (ty*16);
                draw_sprite_part(spr_grassland, ii, tx*64, ty*64, 64, 64, (xx-_xmin)*64, (yy-_ymin)*64);
            }
        }
    }

    if (!ds_map_exists(global.texturemap, _room_cur)) {
        global.texturemap[? _room_cur] = sprite_create_from_surface(surf, 0, 0, global.chunk_size, global.chunk_size, false, false, 0, 0);
    }
    else {
        sprite_add_from_surface(global.texturemap[? _room_cur], surf, 0, 0, global.chunk_size, global.chunk_size, false, false);
    }
    surface_reset_target();
    var srcBuff = buffer_create(global.chunk_surface_bytes, buffer_grow, 1);
    buffer_get_surface(srcBuff, surf, buffer_surface_copy, 0, 0);
    var cmpBuff = buffer_compress(srcBuff,0,global.chunk_surface_bytes);
    buffer_save(cmpBuff,_room_cur+"_"+string(ii)+".dat");
    surface_free(surf);
}

sprite_save_strip(global.texturemap[? _room_cur], _room_cur+".png");

show_debug_message("Texture Writer Done : " + date_time_string(date_current_datetime()));
 

Attachments

Simon Gust

Member
Can you try it with a fixed buffer (instead of a grow buffer), the seek alignment set to 4 and without compressing?
Also check if global.chunk_surface_bytes is exactly (surface_width * surface_height * 4)
 
T

threadom

Guest
Can you try it with a fixed buffer (instead of a grow buffer), the seek alignment set to 4 and without compressing?
Also check if global.chunk_surface_bytes is exactly (surface_width * surface_height * 4)
Simon, i tried like that :

var srcBuff = buffer_create(global.chunk_surface_bytes, buffer_grow, 4);
buffer_get_surface(srcBuff, surf, buffer_surface_copy, 0, 0);
var cmpBuff = buffer_compress(srcBuff,0,global.chunk_surface_bytes);
buffer_save(cmpBuff,_room_cur+"_"+string(ii)+".dat");
surface_free(surf);

but buffer still filled with 4096 value at 0 (null).
surface_width and surface_height are 512 .... hummm . oups

global.chunk_surface_bytes = global.chunk_size*2*4; ... my bad ... my mistake

global.chunk_surface_bytes = sqr(global.chunk_size)*4 will be better ...

upload_2019-8-18_16-1-19.png

upload_2019-8-18_16-2-32.png

look like really bettter, thanks Simon :)
 
Top