Commit 59d4397cd9e0788096497653c1a079f9c210a936

Thomas de Grivel 2024-02-28T10:29:46

wip asan

diff --git a/libc3/window/sdl2/demo/matrix.c b/libc3/window/sdl2/demo/matrix.c
index 85c88ad..4698629 100644
--- a/libc3/window/sdl2/demo/matrix.c
+++ b/libc3/window/sdl2/demo/matrix.c
@@ -229,9 +229,12 @@ bool matrix_text_init (s_tag *tag, f32 y)
   u8_random_uniform(&len, 40);
   len += 10;
   text = gl_vtext_new(&g_matrix_font);
-  if (! text ||
-      ! gl_vtext_render_to_texture_random(text, len))
+  if (! text)
     return false;
+  if (! gl_vtext_render_to_texture_random(text, len)) {
+    gl_vtext_delete(text);
+    return false;
+  }
   map = &tag->data.map;
   tag_init_sym(  map->key + 0, sym_1("spacing"));
   tag_init_f32(map->value + 0, spacing);
@@ -313,7 +316,7 @@ void matrix_text_clean (s_tag *tag)
     assert(! "matrix_text_clean: invalid tag");
     return;
   }
-  gl_vtext_clean(text);
+  gl_vtext_delete(text);
 }
 
 bool matrix_unload (s_sequence *seq)
@@ -322,11 +325,6 @@ bool matrix_unload (s_sequence *seq)
   matrix_screen_clean(&seq->tag);
   tag_void(&seq->tag);
   gl_font_clean(&g_matrix_font);
-  return true;
-}
-
-bool matrix_update (s_sequence *seq)
-{
-  (void) seq;
+  gl_sprite_clean(&g_matrix_shade);
   return true;
 }
diff --git a/libc3/window/sdl2/gl_vtext.c b/libc3/window/sdl2/gl_vtext.c
index 5371f80..5097f12 100644
--- a/libc3/window/sdl2/gl_vtext.c
+++ b/libc3/window/sdl2/gl_vtext.c
@@ -240,9 +240,9 @@ bool gl_vtext_render_to_texture_random (s_gl_text *text, uw len)
   glyphs = calloc(len, sizeof(FT_UInt));
   if (! glyphs) {
     err_puts("gl_vtext_render_to_texture_random:"
-             " failed to allocate memory");
+             " failed to allocate memory (glyphs)");
     assert(! "gl_vtext_render_to_texture_random:"
-             " failed to allocate memory");
+             " failed to allocate memory (glyphs)");
     return false;
   }
   for (i = 0; i < (sw) len; i++) {
@@ -266,7 +266,8 @@ bool gl_vtext_render_to_texture_random (s_gl_text *text, uw len)
   for (i = 0; i < (sw) len; i++) {
     glyph_index = glyphs[i];
     if (FT_Load_Glyph(face, glyph_index, FT_LOAD_RENDER)) {
-      err_write_1("gl_vtext_render_to_texture_random: failed to load glyph: ");
+      err_write_1("gl_vtext_render_to_texture_random:"
+                  " failed to load glyph: ");
       err_inspect_u32(&glyph_index);
       err_write_1("\n");
       continue;
@@ -281,6 +282,14 @@ bool gl_vtext_render_to_texture_random (s_gl_text *text, uw len)
   data_h += line_height * 2;
   data_size = data_w * data_h * 4;
   data = calloc(1, data_size);
+  if (! data) {
+    err_puts("gl_vtext_render_to_texture_random:"
+             " failed to allocate memory (data)");
+    assert(! "gl_vtext_render_to_texture_random:"
+             " failed to allocate memory (data)");
+    free(glyphs);
+    return false;
+  }
   x = 0;
   y = 0;
   for (i = 0; i < (sw) len; i++) {
@@ -310,6 +319,7 @@ bool gl_vtext_render_to_texture_random (s_gl_text *text, uw len)
     }
     y += line_height;
   }
+  free(glyphs);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data_w, data_h, 0, GL_RGBA,
                GL_UNSIGNED_BYTE, data);
   assert(glGetError() == GL_NO_ERROR);