For some reasion the progrem crashes when trying to read data into a pointer to regionVoxel.
However, reading into a voxel allocated on the stack and then copy it over to the regionVoxel works...
// * This is how I call the read_region function
voxel regionVoxel;
...
result = read_region(region_filename.str(), block_dir.str(), ®ionVoxel);
int read_region(string regionFile, string blockDir, voxel *regionVoxel)
{
voxel tmp;
if(file_exists(blockDir.c_str()))
return ABYDOS_TERRAIN_MIXED_REGION;
if(!file_exists(regionFile.c_str()))
return ABYDOS_TERRAIN_READ_ERROR;
FILE *file = openFile(regionFile.c_str());
if(file == NULL)
return ABYDOS_TERRAIN_READ_ERROR;
memset(regionVoxel, 0, sizeof(voxel));
memset(&tmp, 0, sizeof(voxel));
// * In my world, &tmp and *regionVoxel is kind of the same, why a pointer
// * to voxel can not be read, but a pointer when taken by the adress opererator can eludes me.
//fread((void *) regionVoxel->density, 1, 1, file);
//fread((void *) regionVoxel->material, 2, 1, file);
read(&tmp.density, 1, 1, file);
fread(&tmp.material, 2, 1, file);
*regionVoxel = tmp;
closeFile(file);
regionVoxel->material = ntohs(regionVoxel->material);
return ABYDOS_TERRAIN_SHARED_REGION;
}