Skip to content

Commit

Permalink
Fixing array2d resize.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Feb 22, 2024
1 parent eaef5ea commit 4bd9a80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions seika/data_structures/ska_array2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,25 @@ bool ska_array2d_set(SkaArray2D* array2d, size_t x, size_t y, void* newValue) {

void ska_array2d_resize(SkaArray2D* array2d, size_t newX, size_t newY) {
// Reallocate memory for data array
array2d->data = ska_mem_reallocate(array2d->data, newY * sizeof(void*));
for (size_t i = 0; i < newY; i++) {
const size_t width = max(newX, 1);

Check failure on line 46 in seika/data_structures/ska_array2d.c

View workflow job for this annotation

GitHub Actions / build

implicit declaration of function 'max' is invalid in C99 [-Wimplicit-function-declaration]
const size_t height = max(newY, 1);

array2d->data = ska_mem_reallocate(array2d->data, height * sizeof(void*));
for (size_t i = 0; i < height; i++) {
if (i < array2d->size.h) {
// Resize existing rows
array2d->data[i] = ska_mem_reallocate(array2d->data[i], newX * array2d->elementSize);
array2d->data[i] = ska_mem_reallocate(array2d->data[i], width * array2d->elementSize);
} else {
// Allocate memory for new rows
array2d->data[i] = SE_MEM_ALLOCATE_SIZE(newX * array2d->elementSize);
array2d->data[i] = SE_MEM_ALLOCATE_SIZE(width * array2d->elementSize);
}
}

array2d->size = (SKASize2Di){ .w = (int)newX, .h = (int)newY };

if (newX == 0 && newY == 0) {
ska_array2d_reset(array2d);
}
}

void ska_array2d_reset(SkaArray2D* array2d) {
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seika",
"version": "0.0.37",
"version": "0.0.38",
"dependencies": [
{
"name": "sdl2",
Expand Down

0 comments on commit 4bd9a80

Please sign in to comment.