fix bugs in computing pooled allocation sizes (#151)

This commit is contained in:
Patrick McMorris 2020-07-01 05:58:33 -07:00 committed by GitHub
parent 1b1224a230
commit d9ddd1810f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View File

@ -18955,6 +18955,7 @@ NK_LIB void
nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc,
unsigned int capacity)
{
NK_ASSERT(capacity >= 1);
nk_zero(pool, sizeof(*pool));
pool->alloc = *alloc;
pool->capacity = capacity;
@ -18980,7 +18981,8 @@ nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size)
nk_zero(pool, sizeof(*pool));
NK_ASSERT(size >= sizeof(struct nk_page));
if (size < sizeof(struct nk_page)) return;
pool->capacity = (unsigned)(size - sizeof(struct nk_page)) / sizeof(struct nk_page_element);
/* first nk_page_element is embedded in nk_page, additional elements follow in adjacent space */
pool->capacity = 1 + (unsigned)(size - sizeof(struct nk_page)) / sizeof(struct nk_page_element);
pool->pages = (struct nk_page*)memory;
pool->type = NK_BUFFER_FIXED;
pool->size = size;
@ -18998,7 +19000,7 @@ nk_pool_alloc(struct nk_pool *pool)
return 0;
} else {
nk_size size = sizeof(struct nk_page);
size += NK_POOL_DEFAULT_CAPACITY * sizeof(union nk_page_data);
size += (pool->capacity - 1) * sizeof(struct nk_page_element);
page = (struct nk_page*)pool->alloc.alloc(pool->alloc.userdata,0, size);
page->next = pool->pages;
pool->pages = page;
@ -29130,6 +29132,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
/// - [yy]: Minor version with non-breaking API and library changes
/// - [zz]: Bug fix version with no direct changes to API
///
/// - 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes.
/// - 2020/06/04 (4.03.0) - Made nk_combo header symbols optional.
/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug

View File

@ -1,6 +1,6 @@
{
"name": "nuklear",
"version": "4.03.0",
"version": "4.03.1",
"repo": "Immediate-Mode-UI/Nuklear",
"description": "A small ANSI C gui toolkit",
"keywords": ["gl", "ui", "toolkit"],

View File

@ -8,6 +8,7 @@
/// - [yy]: Minor version with non-breaking API and library changes
/// - [zz]: Bug fix version with no direct changes to API
///
/// - 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes.
/// - 2020/06/04 (4.03.0) - Made nk_combo header symbols optional.
/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug

View File

@ -10,6 +10,7 @@ NK_LIB void
nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc,
unsigned int capacity)
{
NK_ASSERT(capacity >= 1);
nk_zero(pool, sizeof(*pool));
pool->alloc = *alloc;
pool->capacity = capacity;
@ -35,7 +36,8 @@ nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size)
nk_zero(pool, sizeof(*pool));
NK_ASSERT(size >= sizeof(struct nk_page));
if (size < sizeof(struct nk_page)) return;
pool->capacity = (unsigned)(size - sizeof(struct nk_page)) / sizeof(struct nk_page_element);
/* first nk_page_element is embedded in nk_page, additional elements follow in adjacent space */
pool->capacity = 1 + (unsigned)(size - sizeof(struct nk_page)) / sizeof(struct nk_page_element);
pool->pages = (struct nk_page*)memory;
pool->type = NK_BUFFER_FIXED;
pool->size = size;
@ -53,7 +55,7 @@ nk_pool_alloc(struct nk_pool *pool)
return 0;
} else {
nk_size size = sizeof(struct nk_page);
size += NK_POOL_DEFAULT_CAPACITY * sizeof(union nk_page_data);
size += (pool->capacity - 1) * sizeof(struct nk_page_element);
page = (struct nk_page*)pool->alloc.alloc(pool->alloc.userdata,0, size);
page->next = pool->pages;
pool->pages = page;