changed array size to no longer be a pointer, need to check every file that references array to hopefully not have broken anything

This commit is contained in:
herbglitch 2023-07-07 00:58:23 -06:00
parent 56a4aa9d39
commit 533541b852
6 changed files with 29 additions and 24 deletions

View file

@ -36,9 +36,8 @@ uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){
}
*value = malloc(sizeof(ARC_Array));
((ARC_Array *)*value)->data = malloc(sizeof(ARC_Array *) * height);
((ARC_Array *)*value)->size = malloc(sizeof(uint32_t) );
*((ARC_Array *)*value)->size = height;
((ARC_Array *)*value)->data = malloc(sizeof(ARC_Array *) * height);
((ARC_Array *)*value)->size = height;
uint32_t index = 0;
for(uint32_t y = 0; y < height; y++){
@ -65,8 +64,7 @@ uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){
((ARC_Array **)((ARC_Array *)*value)->data)[y] = (ARC_Array *) malloc(sizeof(ARC_Array));
((ARC_Array **)((ARC_Array *)*value)->data)[y]->data = malloc(sizeof(int32_t ) * width);
((ARC_Array **)((ARC_Array *)*value)->data)[y]->size = malloc(sizeof(uint32_t) );
*((ARC_Array **)((ARC_Array *)*value)->data)[y]->size = width;
((ARC_Array **)((ARC_Array *)*value)->data)[y]->size = width;
for(uint32_t i = index; i < fileData->length; i++){
if(fileData->data[i] != ',' && fileData->data[i] != '\n'){
@ -92,13 +90,11 @@ uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){
void ARC_CSV_Delete(ARC_Config *config, ARC_String *string, void *value){
ARC_Array *valueArray = value;
for(uint32_t i = 0; i < *valueArray->size; i++){
for(uint32_t i = 0; i < valueArray->size; i++){
free((int32_t *)((ARC_Array **)valueArray->data)[i]->data);
free((uint32_t *)((ARC_Array **)valueArray->data)[i]->size);
free((ARC_Array *)((ARC_Array **)valueArray->data)[i]);
}
free((ARC_Array **)valueArray->data);
free((uint32_t *)valueArray->size);
free(valueArray);
}

View file

@ -265,9 +265,8 @@ uint8_t ARC_RectArray_Read(ARC_Config* config, ARC_String *string, void **value)
}
*value = malloc(sizeof(ARC_Array));
((ARC_Array *) *value)->data = malloc(sizeof(ARC_Rect) * arraySize);
((ARC_Array *) *value)->size = malloc(sizeof(uint32_t));
*((ARC_Array *) *value)->size = arraySize;
((ARC_Array *) *value)->data = malloc(sizeof(ARC_Rect) * arraySize);
((ARC_Array *) *value)->size = arraySize;
uint64_t index = 0;
arraySize = 0;
@ -291,13 +290,13 @@ uint8_t ARC_RectArray_Read(ARC_Config* config, ARC_String *string, void **value)
index = i + 1;
if(arraySize == *((ARC_Array *) *value)->size){
if(arraySize == ((ARC_Array *) *value)->size){
break;
}
}
}
if(arraySize != *((ARC_Array *) *value)->size){
if(arraySize != ((ARC_Array *) *value)->size){
ARC_RectArray_ReadRect(config, stripped, index, stripped->length - index, &arraySize, value);
}
ARC_String_Destroy(stripped);
@ -449,7 +448,7 @@ uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){
// Scale frames to match spritesheet size
// TODO: possible bug for sheets that use same frames
if(spritesheet->size){
for(uint32_t i = 0; i < *frames->size; i++){
for(uint32_t i = 0; i < frames->size; i++){
((ARC_Rect *)frames->data)[i].x *= *spritesheet->size;
((ARC_Rect *)frames->data)[i].y *= *spritesheet->size;
((ARC_Rect *)frames->data)[i].w *= *spritesheet->size;

View file

@ -38,7 +38,7 @@ void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Re
void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){
++*sprite->frameIndex;
if(*sprite->frameIndex == *sprite->frames->size){
if(*sprite->frameIndex == sprite->frames->size){
*sprite->frameIndex = 0;
}
}
@ -47,4 +47,8 @@ ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){
return (ARC_Rect *)sprite->frames->data + *sprite->frameIndex;
}
ARC_Array *ARC_Sprite_GetAllBounds(ARC_Sprite *sprite){
return sprite->frames;
}
#endif // ARC_SDL

View file

@ -250,9 +250,8 @@ uint8_t ARC_ConfigKey_Read_StringArray(ARC_Config* config, ARC_String *string, v
}
*value = malloc(sizeof(ARC_Array));
((ARC_Array *) *value)->data = malloc(sizeof(ARC_String *) * arraySize);
((ARC_Array *) *value)->size = malloc(sizeof(uint32_t));
*((ARC_Array *) *value)->size = arraySize;
((ARC_Array *) *value)->data = malloc(sizeof(ARC_String *) * arraySize);
((ARC_Array *) *value)->size = arraySize;
uint64_t index = 0;
arraySize = 0;
@ -265,13 +264,13 @@ uint8_t ARC_ConfigKey_Read_StringArray(ARC_Config* config, ARC_String *string, v
index = i + 1;
if(arraySize == *((ARC_Array *) *value)->size){
if(arraySize == ((ARC_Array *) *value)->size){
break;
}
}
}
if(arraySize != *((ARC_Array *) *value)->size){
if(arraySize != ((ARC_Array *) *value)->size){
ARC_ConfigKey_StringArray_ReadString(config, stripped, index, stripped->length - index, &arraySize, value);
}
ARC_String_Destroy(stripped);
@ -337,7 +336,7 @@ void ARC_ConfigKey_Delete_String(ARC_Config *config, ARC_String *string, void *v
}
void ARC_ConfigKey_Delete_StringArray(ARC_Config *config, ARC_String *string, void *value){
for(uint32_t i = 0; i < *((ARC_Array *)value)->size; i++){
for(uint32_t i = 0; i < ((ARC_Array *)value)->size; i++){
free(((ARC_String **)((ARC_Array *)value)->data)[i]);
}
free((ARC_Array *)value);