[osg-users] 3D osg::Image allocation size problem

Josiah Jideani josh.jideani at gmail.com
Fri Jul 22 04:00:04 PDT 2016


I am developing a scientific visualization application using Qt and Openscenegraph.  I am trying to create a 3D osg::Image to add to an osgVolume.  I am having problems allocating the image data when I call the allocateImage member function (see the code snippet below).

The allocation works for equal dimensions less than 640.

When I try to allocate anything above 640x640x640 but less than 800x800x800, it seems to allocate successfully because image_s, image_t and image_r hold the correct sizes however when I try to write to the image data (the nested for loops) a segmentation fault is thrown at data[0] = 0.0f when s = 0; t = 0; and r = some random but valid number.

I can allocate and write to the image data with sizes between 800x800x800 and 1024x1024x1024, but a segmentation fault is thrown from the object code after the call to the viewer's frame() method.

And finally for sizes above 1024 the allocation completely fails as image_s image_t and image_r all hold 0.

Any clue on how to solve this? It was my understanding that the maximum size of the image is limited by the maximum 3D texture size of the graphics card which for the Quadro K4200 that I'm using is 4096x4096x4096.  So why am I only able to allocate a 640x640x640 image?

These are the specifications of my system:
Operating system: Opensuse Leap 42.1
RAM: 128GB
Graphics Card: Quadro K4200
Qt: Qt 4.7.1
OSG version: 3.2.3

Thank you!



osg::ref_ptr<osg::Image> image = new osg::Image
image->allocateImage(1024, 1024, 1024, GL_RGBA, GL_FLOAT);

int image_s = image->s();
int image_t = image->t();
int image_r = image->r();

for(int s = 0; s < image_s; s++)
    for(int t = 0; t < image_t; t++)
        for(int r = 0; r < image_r; r++)
            float* data = (float*) image->data(s,t,r);
            data[0] = 0.0f;
            data[1] = 0.0f;
            data[2] = 1.0f;
            data[3] = 0.1f;

Read this topic online here:

More information about the osg-users mailing list