Hi,
I created a previous thread of re-sizing dynamic arrays.
I got the answers to that question and I could re-size the dynamic arrays but when I tried to apply similar steps to creating a dynamic array of struct, my program compiles but crashes when i try to run it.
--------------outside main function----------------
typedef struct{
sprite _sprite;
/*
float x_pos;
float y_pos;
vector vec;
*/
}sprites;
------------in main function--------------
int initial_num_bricks = 1;
sprites *sprites_pointer = NULL;
sprites_pointer = (sprites *)malloc(initial_num_bricks * (sizeof(sprites)));
populate_bricks(bitmap_names, sprites_pointer, initial_num_bricks);
-------------------populate_bricks procedure--------------
void populate_bricks(const char **_sprite_bmap_names, sprites *sprites_pointer, int &sprites_size){
//bmap = randomly_select_sprite_bitmap(_sprite_bmap_names, BRICKS_SIZE);
int sprites_counter = 0;
sprites_pointer[sprites_counter]._sprite = create_sprite(bitmap_named("red_brick"));
initi_sprite_settings(sprites_pointer[sprites_counter]._sprite, random_x_pos, y_pos, vector_to(0, 0));
sprites_size++;
sprites *temp_ = (sprites*) realloc (sprites_pointer, (sprites_size) * sizeof(sprites));
if(temp_ != NULL){
sprites_pointer = temp_;
}
sprites_counter++;
}
Can anyone see what I am doing wrong?
Thanks