Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

nk_context commands buffer pollutes on skipping rendering.

Open xeechou opened this issue 5 years ago • 2 comments

Hi, I am having issues with optimizing render loop with memcmp(cmds, last, cmds->allocated), if I am getting 0 then I call nk_clear(ctx) directly as documentation suggested.

But later at some point of rendering I found out I would have problems with cmds. I am getting garbage cmd->type and very big cmd->next, especially in the case of pop-up windows. It seems I need to call nk_foreach regardless I want to render or not before calling nk_clear(ctx). I digged a bit and found that there was a nk_build function underneath that changes the command buffer.

I am not sure if this is the issue but I found calling a dummy nk_foreach is like a hack. Is there a better way doing it?

xeechou avatar Apr 01 '20 17:04 xeechou

Are you able to provide compileable source code that reproduces this problem? That would make it a lot easier to debug.

Hejsil avatar Apr 01 '20 18:04 Hejsil

Hello!

This is quite an old canned thread, but I seem to be running into a similar issue, although even when rendering each frame.

I have toggled NK_INCLUDE_VERTEX_BUFFER_OUTPUT and have a single window with a nk_label call inside. The context's memory seems to be getting filled correctly prior to calling nk_convert, with allocated tracking the correct amount of bytes. However, inside the nk_convert call during the processing of the first NK_COMMAND_RECT_FILLED command, the cmds buffer that I have initialized Nuklear with, points to the same memory as the context/window, but has allocated as 0, which eventually leads nk_draw_list_alloc_path to return a pointer to the same command that is currently being processed within nk_foreach, thus corrupting cmd's type and next command offset, leading to nk__end not processing further commands.

I have seemingly worked around this by storing the next command offset at the start of each nk_foreach loop and passing it to nk__end, but I have a feeling I might be missing something.

This issue is resulting for me in only the bare window top bar showing and nothing else. Notably, having more than 1 window seems to be working fine.

TimsonL avatar May 23 '25 13:05 TimsonL