tinycoffee
tinycoffee copied to clipboard
getting a resource multiple times causes side effects
Test code:
-- in nelua
##[[
TICO = {
L = '../../tinycoffee/build',
I = {
include = "../../tinycoffee/include",
external = "../../tinycoffee/external"
},
}
]]
require 'tico'
local nelua_argc: cint <cimport, nodecl>
local nelua_argv: *[0]cstring <cimport, nodecl>
local config = tico.config_load('project.tico', nelua_argc, nelua_argv)
--local config = tico.config_init('mytest', 800, 600, nelua_argc, nelua_argv)
tico.init(config)
for i = 1, 10 do
local res = tico.plugin_resources_get('image', 'lunarlander')
end
while not tico.window_should_close() do
tico.update()
tico.begin_draw()
tico.graphics_clear(tico.BG)
tico.end_draw()
end
tico.terminate()
(this generates this C code)
// some typedefs:
static char __strlit1[13] = "project.tico";
typedef char** nlcstring_ptr;
typedef tc_Resource* tc_Resource_ptr;
static char __strlit2[6] = "image";
static char __strlit3[12] = "lunarlander";
static tc_Color tico_tico_BG = {75U, 90U, 90U, 255U};
/// [...]
testes_config = tico_config_load(__strlit1, nelua_argc, (nlcstring_ptr)nelua_argv);
tico_init(&testes_config);
for(int64_t i = 1; i <= 10; i = i + 1) {
tc_Resource_ptr res = tico_plugin_resources_get(__strlit2, __strlit3);
}
while(!tico_window_should_close()) {
tico_update();
tico_begin_draw();
tico_graphics_clear(tico_tico_BG);
tico_end_draw();
}
tico_terminate();
return 0;
// [...]
Behaviour
Running this code will give this error at exit:
[...]
19:38:47 Render Module terminated
19:38:47 Graphics Module terminated
Thread 1 "testes" received signal SIGSEGV, Segmentation fault.
0x00007ffff69b884f in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#0 0x00007ffff69b884f in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#1 0x00007ffff69b8dc6 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#2 0x00007ffff6784e9d in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#3 0x00007ffff67b3adf in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#4 0x00007ffff66cfa5d in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#5 0x00007ffff6594f78 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#6 0x00007ffff6630517 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#7 0x00007ffff74aefb3 in ?? () from /lib/x86_64-linux-gnu/libGLX_mesa.so.0
#8 0x00007ffff7499539 in ?? () from /lib/x86_64-linux-gnu/libGLX_mesa.so.0
#9 0x000055555567d625 in destroyContextGLX (window=0x555555b477c0) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/external/glfw/src/glx_context.c:241
241 glXDestroyContext(_glfw.x11.display, window->context.glx.handle);
#10 0x00005555556790f1 in _glfwPlatformDestroyWindow (window=0x555555b477c0) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/external/glfw/src/x11_window.c:2055
2055 window->context.destroy(window);
#11 0x000055555566e41a in glfwDestroyWindow (handle=0x555555b477c0) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/external/glfw/src/window.c:459
459 _glfwPlatformDestroyWindow(window);
#12 0x00005555555bce28 in tico_window_deinit (window=0x55555585ce68 <Core+24360>) at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/src/window.c:48
48 glfwDestroyWindow(window->handle);
#13 0x0000555555564681 in tico_terminate () at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/src/core.c:230
230 tico_window_deinit(&Core.window);
#14 0x0000555555563265 in nelua_main (nelua_argc=1, nelua_argv=0x7fffffffde38) at nelua_cache/testes.c:133
133 tico_terminate();
#15 0x00005555555632a4 in main (argc=1, argv=0x7fffffffde38) at nelua_cache/testes.c:137
137 return nelua_main(argc, argv);
However, changing the for
count will create other errors, for instance, changing from 10
to 13
will give this error at startup:
19:40:54 Lua lib: editor added
19:40:54 Plugin: editor enabled
malloc(): unaligned tcache chunk detected
Thread 1 "testes" hit Breakpoint 1, __GI_abort () at abort.c:49
49 abort.c: Arquivo ou diretório inexistente.
#0 __GI_abort () at abort.c:49
49 in abort.c
#1 0x00007ffff7910af6 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7a38128 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
155 ../sysdeps/posix/libc_fatal.c: Arquivo ou diretório inexistente.
#2 0x00007ffff791946c in malloc_printerr (str=str@entry=0x7ffff7a3abf0 "malloc(): unaligned tcache chunk detected") at malloc.c:5389
5389 malloc.c: Arquivo ou diretório inexistente.
#3 0x00007ffff791e85c in tcache_get (tc_idx=<optimized out>) at malloc.c:2953
2953 in malloc.c
#4 __GI___libc_malloc (bytes=88) at malloc.c:3071
3071 in malloc.c
#5 0x00007ffff69b8b11 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#6 0x00007ffff696e50a in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#7 0x00007ffff696ebc9 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#8 0x00007ffff6930065 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#9 0x00007ffff68a3532 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#10 0x00007ffff67ae782 in ?? () from /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
#11 0x00005555556d9366 in ImGui_ImplOpenGL3_CreateDeviceObjects ()
#12 0x00005555556d817b in ImGui_ImplOpenGL3_NewFrame ()
#13 0x0000555555563a52 in tico_imgui_update () at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/include/tico_imgui.h:50
50 ImGui_ImplOpenGL3_NewFrame();
#14 0x00005555555646cd in tico_update () at /home/dreunix/origami-sword/momonave/rotor-quick/tinycoffee/src/core.c:242
242 tico_imgui_update();
#15 0x000055555556322c in nelua_main (nelua_argc=1, nelua_argv=0x7fffffffde38) at nelua_cache/testes.c:128
128 tico_update();
#16 0x00005555555632a4 in main (argc=1, argv=0x7fffffffde38) at nelua_cache/testes.c:137
137 return nelua_main(argc, argv);
I remember that there is another one which gives an error on miniaudio
, which also makes the game's sound a little weird.