Hi Ulrich,
The code for reading file is my testing data and I copied the data from one
format to unsigned char format, so the file won't contain more data than I
expected.
Thanks for your suggestion. It works if I increased the size for malloc,
but I don't understand. It is very helpful if you can answer the following
questions:
1. when i changed to malloc(nx * ny * nz * 8 * (sizeof(unsigned char))), it
works, but it doesn't work if I changed 8 to 4.
2. why I need to assign the memory with data's size * 8. is it for RBGA each
2 bit extra data?
3. why osg will excess the data I assigned into Image? I guess osg is just
reading from the data I assigned only.
4. what is the different between osg::Image::NO_DELETE,
osg::Image::USE_NEW_DELETE and osg::Image::USE_MALLOC_FREE?
Many thanks for your help.
Regards,
Clement
________________________________________
From: [email protected]
[[email protected]] On Behalf Of Ulrich Hertlein
[[email protected]]
Sent: Thursday, 1 September 2011 5:24 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] setImage error
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
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org