Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions demo/sdl3_renderer/nuklear_sdl3_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,7 @@ NK_INTERN void *
nk_sdl_alloc(nk_handle user, void *old, nk_size size)
{
NK_UNUSED(user);
/* FIXME: nk_sdl_alloc should use SDL_realloc here, not SDL_malloc
* but this could cause a double-free due to bug within Nuklear, see:
* https://github.com/Immediate-Mode-UI/Nuklear/issues/768
* */
#if 0
return SDL_realloc(old, size);
#else
NK_UNUSED(old);
return SDL_malloc(size);
#endif
}

NK_INTERN void
Expand Down
24 changes: 17 additions & 7 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -8524,7 +8524,16 @@ NK_LIB void*
nk_malloc(nk_handle unused, void *old,nk_size size)
{
NK_UNUSED(unused);
NK_UNUSED(old);
/*
* Due to historical reasons, Nuklear always calls alloc(user,old,size)
* with the "old" pointer always being NULL. For full explanation, see:
* https://github.com/Immediate-Mode-UI/Nuklear/issues/768
*
* FIXME: The best would be to replace this function with "nk_realloc",
* but some custom allocators could still depend on "malloc" assumption
* so changing this now (without major bump) would break existing code.
*/
NK_ASSERT(!old && "Nuklear's internal code must never call realloc !");
return malloc(size);
}
NK_LIB void
Expand Down Expand Up @@ -8617,15 +8626,16 @@ nk_buffer_realloc(struct nk_buffer *b, nk_size capacity, nk_size *size)
return 0;

buffer_size = b->memory.size;
temp = b->pool.alloc(b->pool.userdata, b->memory.ptr, capacity);
NK_ASSERT(capacity >= buffer_size && "shrinking was never supported here");

/* HACK: this simulates realloc with malloc+memcpy+free
* for backwards compatibility reasons, see the note in nk_malloc */
temp = b->pool.alloc(b->pool.userdata, 0, capacity);
NK_ASSERT(temp);
if (!temp) return 0;

*size = capacity;
if (temp != b->memory.ptr) {
NK_MEMCPY(temp, b->memory.ptr, buffer_size);
b->pool.free(b->pool.userdata, b->memory.ptr);
}
NK_MEMCPY(temp, b->memory.ptr, buffer_size);
b->pool.free(b->pool.userdata, b->memory.ptr);

if (b->size == buffer_size) {
/* no back buffer so just set correct size */
Expand Down
24 changes: 17 additions & 7 deletions src/nuklear_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ NK_LIB void*
nk_malloc(nk_handle unused, void *old,nk_size size)
{
NK_UNUSED(unused);
NK_UNUSED(old);
/*
* Due to historical reasons, Nuklear always calls alloc(user,old,size)
* with the "old" pointer always being NULL. For full explanation, see:
* https://github.com/Immediate-Mode-UI/Nuklear/issues/768
*
* FIXME: The best would be to replace this function with "nk_realloc",
* but some custom allocators could still depend on "malloc" assumption
* so changing this now (without major bump) would break existing code.
*/
NK_ASSERT(!old && "Nuklear's internal code must never call realloc !");
return malloc(size);
}
NK_LIB void
Expand Down Expand Up @@ -104,15 +113,16 @@ nk_buffer_realloc(struct nk_buffer *b, nk_size capacity, nk_size *size)
return 0;

buffer_size = b->memory.size;
temp = b->pool.alloc(b->pool.userdata, b->memory.ptr, capacity);
NK_ASSERT(capacity >= buffer_size && "shrinking was never supported here");

/* HACK: this simulates realloc with malloc+memcpy+free
* for backwards compatibility reasons, see the note in nk_malloc */
temp = b->pool.alloc(b->pool.userdata, 0, capacity);
NK_ASSERT(temp);
if (!temp) return 0;
Comment thread
RobLoach marked this conversation as resolved.

*size = capacity;
if (temp != b->memory.ptr) {
NK_MEMCPY(temp, b->memory.ptr, buffer_size);
b->pool.free(b->pool.userdata, b->memory.ptr);
}
NK_MEMCPY(temp, b->memory.ptr, buffer_size);
Comment thread
sleeptightAnsiC marked this conversation as resolved.
b->pool.free(b->pool.userdata, b->memory.ptr);

if (b->size == buffer_size) {
/* no back buffer so just set correct size */
Expand Down
Loading