Hi Clement,

On 31/08/11 19:22 , [email protected] wrote:
>   Here is my code: (If nx, ny, nz are used a small number such as 50, 50, 20, 
> the error is gone)
> 
>       int nx = 350;
>       int ny = 350;
>       int nz = 60;
> 
>         unsigned char pdisp_ptr = (unsigned char*)malloc(nx * ny * nz * 
> (sizeof(unsigned char)));

I assume that's a 'unsigned char* pdisp_ptr'.

>       FILE *pf = fopen("data.txt", "r");
>       unsigned int dt;
>       int count = 0;
> 
>       while (!feof(pf)) {
>               fscanf_s(pf, "%X", &dt);
>               *pdisp_ptr++ = dt;
>               count++;
>               if (count == nz) {
>                       count = 0;
>               }
>       }
>       fclose(pf);

First of all, you could easily corrupt memory, if the file contains more data 
than you expect.

>        image->setImage(nx, ny, nz, 4, GL_RGBA, GL_UNSIGNED_BYTE, pdisp_ptr, 
> osg::Image::NO_DELETE); 

The data buffer you've created is not big enough to hold nx*ny*nz samples of 
RGBA data.

Either you're reading more than expected (reading nx*ny*nz*4 into a nx*ny*nz 
buffer) and
corrupt memory or you're telling OSG that it can read nx*ny*nz*4 bytes out of a 
nx*ny*nz
buffer.

Cheers,
/ulrich
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to