From: hgn Date: Sun, 21 Jan 2024 08:36:55 +0000 (+0000) Subject: race condition with development tools.. X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=183961c84950614b04ccc39455fc101da0e2dc82 race condition with development tools.. --- diff --git a/vg_lines.h b/vg_lines.h index d7f277a..5511875 100644 --- a/vg_lines.h +++ b/vg_lines.h @@ -72,18 +72,15 @@ struct{ } static vg_lines; +#define VG_LINES_BUFFER_SIZE 50000 * sizeof( struct vg_lines_vert ) + static void async_vg_lines_init( void *payload, u32 payload_size ){ glGenVertexArrays( 1, &vg_lines.vao ); glGenBuffers( 1, &vg_lines.vbo ); glBindVertexArray( vg_lines.vao ); glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo ); - u32 size = 50000 * sizeof( struct vg_lines_vert ); - - vg_lines.vertex_buffer = - vg_create_linear_allocator(vg_mem.rtmemory, size, VG_MEMORY_REALTIME); - - glBufferData( GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW ); + glBufferData( GL_ARRAY_BUFFER, VG_LINES_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW ); glBindVertexArray( vg_lines.vao ); VG_CHECK_GL_ERR(); @@ -113,12 +110,15 @@ static void async_vg_lines_init( void *payload, u32 payload_size ){ } static void vg_lines_init(void){ + vg_lines.vertex_buffer = + vg_create_linear_allocator( vg_mem.rtmemory, + VG_LINES_BUFFER_SIZE, VG_MEMORY_REALTIME); + vg_async_call( async_vg_lines_init, NULL, 0 ); vg_console_reg_var( "vg_lines", &vg_lines.draw, k_var_dtype_i32, VG_VAR_CHEAT ); vg_shader_register( &_shader_lines ); - } static void vg_lines_drawall( void ){ diff --git a/vg_mem.h b/vg_mem.h index 48969d9..6aa22f2 100644 --- a/vg_mem.h +++ b/vg_mem.h @@ -331,7 +331,17 @@ static void vg_linear_clear( void *buffer ) alloc->cur = 0; } -/* allocate a FIXED SIZE linear allocator */ +/* allocate a FIXED SIZE linear allocator + * + * FIXME: there was a bug in vg's code that caused a race condition between + * two system allocations. make this IMPOSSIBLE by requiring a lock + * on the allocater to be passed between threads. + * + * luckily that bug only exists when using development tools, but still! + * + * this should then only be checked and turned on in debugging. + * + */ static void *_vg_create_linear_allocator( void *lin_alloc, u32 size, u16 flags, const char *constr_name) {