nurbssurface
Merkna Chee-Orts - LMO
mchee at lsr-vax.UUCP
Mon May 20 23:09:37 AEST 1991
Hello,
I am hoping that someone may be able to help me with a problem I
am having when using the nurbssurface function. If I create the array which
holds the control points using malloc or calloc, my program crashes giving
a bus error. If that array has been statically allocated the program works.
I know that malloc or calloc do not allocate memory contiguously and so I
have allocated the memory for the 3D control points array from one large
block of memory. That however does not seem to solve the problem. I have
listed the parts of my code which are pertinent.
Thanks in advance.
/* some declarations.. */
int NUM_SPOINTS; /* # of control pts in s dimension */
int NUM_TPOINTS; /* # of control pts in t dimension */
int NUMCOORDS; /* # of coordinate space */
double ***ctl_pts; /* pointer to array of control pts */
double ***dtensor(); /* function that allocates memory */
/* within the code ... */
ctl_pts=dtensor(NUM_SPOINTS, NUM_TPOINTS, NUMCOORDS);
/* function dtensor.... */
double ***dtensor(n1, n2, n3)
int n1, n2, n3;
{
int i, j, k, l;
double *t, ***tt;
/* allocates a block of size (n1)*(n2)*(n3) */
t=(double *)malloc((unsigned)(n1*n2*n3)*sizeof(double));
if(!t)
{
printf("allocation failure in dtensor()\n");
exit(0);
}
tt=(double ***)malloc((unsigned)n1*sizeof(double **));
for(i=0; i<n1; i++)
tt[i]=(double **)malloc((unsigned)n2*sizeof(double *));
for(i=0; i<n1; i++)
for(j=0; j<n2; j++)
tt[i][j]=t+(n2*n3*i)+n3*j;
return tt;
}
/* calling the nurbssurface function...*/
bgnsurface();
nurbssurface(
NUM_SKNOTS, sknots,
NUM_TKNOTS, tknots,
sizeof(double)*NUM_TPOINTS*NUMCOORDS,
sizeof(double)*NUMCOORDS,
ctl_pts,
ORDER, ORDER,
N_V3D
);
endsurface();
More information about the Comp.sys.sgi
mailing list