race condition with development tools..
authorhgn <hgodden00@gmail.com>
Sun, 21 Jan 2024 08:36:55 +0000 (08:36 +0000)
committerhgn <hgodden00@gmail.com>
Sun, 21 Jan 2024 08:36:55 +0000 (08:36 +0000)
vg_lines.h
vg_mem.h

index d7f277ad70347703de64f1804b1597ebb74ae61d..5511875b9f058747c30afce32d7f40d13cb09049 100644 (file)
@@ -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 ){
index 48969d9d13be9588f811b898f9454fd9de96c609..6aa22f273abfec1878cd22914a295540149d8d83 100644 (file)
--- 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)
 {