diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-02-08 16:55:31 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-02-08 16:55:31 +0300 |
commit | ec7df03c867d28316708e9b91bec5cef0aee832e (patch) | |
tree | 3f560939b745032e235d9ac789c4117d669d6462 /source/blender/render/intern | |
parent | 4c318539b2f6abdf8f2a02376b6fcb8d30a4b12e (diff) |
Warning fixes, one actual bug found in sequencer sound wave drawing. Also
changed some malloc to MEM_mallocN while trying to track down a memory leak.
Diffstat (limited to 'source/blender/render/intern')
-rw-r--r-- | source/blender/render/intern/raytrace/rayobject.cpp | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/voxeldata.c | 50 |
2 files changed, 33 insertions, 19 deletions
diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index 869405e0fbc..ac386e776b4 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -180,7 +180,7 @@ static inline int rayface_check_cullface(RayFace *face, Isect *is) /* this function shall only modify Isect if it detects an hit */ static int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *is) { - float co1[3],co2[3],co3[3],co4[3]; + float co1[3],co2[3],co3[3],co4[3]={0}; float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22,r0,r1,r2; float m0, m1, m2, divdet, det1; float labda, u, v; diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index 1a220f6e9b1..f6da090f95b 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -57,29 +57,40 @@ #include "texture.h" #include "voxeldata.h" -void load_frame_blendervoxel(FILE *fp, float *F, int size, int frame, int offset) +static int load_frame_blendervoxel(FILE *fp, float *F, int size, int frame, int offset) { - fseek(fp,frame*size*sizeof(float)+offset,0); - fread(F,sizeof(float),size,fp); + if(fseek(fp,frame*size*sizeof(float)+offset,0) == -1) + return 0; + if(fread(F,sizeof(float),size,fp) != size) + return 0; + + return 1; } -void load_frame_raw8(FILE *fp, float *F, int size, int frame) +static int load_frame_raw8(FILE *fp, float *F, int size, int frame) { char *tmp; int i; tmp = (char *)MEM_mallocN(sizeof(char)*size, "temporary voxel file reading storage"); - fseek(fp,(frame-1)*size*sizeof(char),0); - fread(tmp, sizeof(char), size, fp); + if(fseek(fp,(frame-1)*size*sizeof(char),0) == -1) { + MEM_freeN(tmp); + return 0; + } + if(fread(tmp, sizeof(char), size, fp) != size) { + MEM_freeN(tmp); + return 0; + } for (i=0; i<size; i++) { F[i] = (float)tmp[i] / 256.f; } MEM_freeN(tmp); + return 1; } -void load_frame_image_sequence(Render *re, VoxelData *vd, Tex *tex) +static void load_frame_image_sequence(Render *re, VoxelData *vd, Tex *tex) { ImBuf *ibuf; Image *ima = tex->ima; @@ -133,26 +144,25 @@ void load_frame_image_sequence(Render *re, VoxelData *vd, Tex *tex) } } -void write_voxeldata_header(struct VoxelDataHeader *h, FILE *fp) -{ - fwrite(h,sizeof(struct VoxelDataHeader),1,fp); -} - -void read_voxeldata_header(FILE *fp, struct VoxelData *vd) +static int read_voxeldata_header(FILE *fp, struct VoxelData *vd) { VoxelDataHeader *h=(VoxelDataHeader *)MEM_mallocN(sizeof(VoxelDataHeader), "voxel data header"); rewind(fp); - fread(h,sizeof(VoxelDataHeader),1,fp); + if(fread(h,sizeof(VoxelDataHeader),1,fp) != 1) { + MEM_freeN(h); + return 0; + } vd->resol[0]=h->resolX; vd->resol[1]=h->resolY; vd->resol[2]=h->resolZ; MEM_freeN(h); + return 1; } -void init_frame_smoke(Render *re, VoxelData *vd, Tex *tex) +static void init_frame_smoke(Render *re, VoxelData *vd, Tex *tex) { Object *ob; ModifierData *md; @@ -224,7 +234,7 @@ void init_frame_smoke(Render *re, VoxelData *vd, Tex *tex) } } -void cache_voxeldata(struct Render *re,Tex *tex) +static void cache_voxeldata(struct Render *re,Tex *tex) { VoxelData *vd = tex->vd; FILE *fp; @@ -246,8 +256,12 @@ void cache_voxeldata(struct Render *re,Tex *tex) fp = fopen(vd->source_path,"rb"); if (!fp) return; - if (vd->file_format == TEX_VD_BLENDERVOXEL) - read_voxeldata_header(fp, vd); + if (vd->file_format == TEX_VD_BLENDERVOXEL) { + if(!read_voxeldata_header(fp, vd)) { + fclose(fp); + return; + } + } size = (vd->resol[0])*(vd->resol[1])*(vd->resol[2]); vd->dataset = MEM_mapallocN(sizeof(float)*size, "voxel dataset"); |