Skip to content

Commit

Permalink
fix shared mem misalignment error, close #118
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jul 8, 2021
1 parent 7f8a2ac commit 53d7ac0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/mcx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1696,19 +1696,22 @@ int mcx_loadjson(cJSON *root, Config *cfg){

val=FIND_JSON_OBJ("InverseCDF","Domain.InverseCDF",Domain);
if(val){
cfg->nphase=cJSON_GetArraySize(val)+2; /*left-/right-ends are excluded, so added 2*/
int nphase=cJSON_GetArraySize(val);
cfg->nphase=nphase+2; /*left-/right-ends are excluded, so added 2*/
cfg->nphase+=(cfg->nphase & 0x1); /* make cfg.nphase even number */
if(cfg->invcdf)
free(cfg->invcdf);
cfg->invcdf=(float*)calloc(cfg->nphase,sizeof(float));
cfg->invcdf[0]=-1.f; /*left end is always -1.f,right-end is always 1.f*/
vv=val->child;
for(i=1;i<cfg->nphase-1;i++){
for(i=1;i<=nphase;i++){
cfg->invcdf[i]=vv->valuedouble;
vv=vv->next;
if(cfg->invcdf[i]<cfg->invcdf[i-1] || (cfg->invcdf[i]>1.f || cfg->invcdf[i]<-1.f))
MCX_ERROR(-1,"Domain.InverseCDF contains invalid data; it must be a monotonically increasing vector with all values between -1 and 1");
}
cfg->invcdf[cfg->nphase-1]=1.f; /*left end is always -1.f,right-end is always 1.f*/
cfg->invcdf[nphase+1]=1.f; /*left end is always -1.f,right-end is always 1.f*/
cfg->invcdf[cfg->nphase-1]=1.f;
}

val=FIND_JSON_OBJ("VoxelSize","Domain.VoxelSize",Domain);
Expand Down
4 changes: 3 additions & 1 deletion src/mcxlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ void mcx_set_field(const mxArray *root,const mxArray *item,int idx, Config *cfg)
double *val=mxGetPr(item);
if(cfg->invcdf) free(cfg->invcdf);
cfg->nphase=(unsigned int)nphase+2;
cfg->nphase+=(cfg->nphase & 0x1); // make cfg.nphase even number
cfg->invcdf=(float*)calloc(cfg->nphase,sizeof(float));
for(i=0;i<nphase;i++){
cfg->invcdf[i+1]=val[i];
Expand All @@ -729,7 +730,8 @@ void mcx_set_field(const mxArray *root,const mxArray *item,int idx, Config *cfg)
}
cfg->invcdf[0]=-1.f;
cfg->invcdf[nphase+1]=1.f;
printf("mcx.invcdf=[%ld];\n",nphase);
cfg->invcdf[cfg->nphase-1]=1.f;
printf("mcx.invcdf=[%ld];\n",cfg->nphase);
}else if(strcmp(name,"shapes")==0){
int len=mxGetNumberOfElements(item);
if(!mxIsChar(item) || len==0)
Expand Down

0 comments on commit 53d7ac0

Please sign in to comment.