Drawing voxels problem - VoxelClient_VisDrawer


I have successfully tested the "voxeldemo" sample, located in the samples folder of OCC6.6, but now I am trying to create my own code to draw voxels but the next function in VoxelClient_VisDrawer is failing:

static OpenGl_Element* VisDrawerCallBack (const Graphic3d_CUserDraw* theUserDraw)
if (theUserDraw == 0)
return 0;

// Retrieve the user structure
Voxel_VisData* aUserData = (Voxel_VisData*) (theUserDraw->Data);

if (aUserData == 0)
return 0;

VoxelClient_VisDrawer::VisElement *aElem =
new VoxelClient_VisDrawer::VisElement (aUserData);

if (theUserDraw->Bounds != 0)
aElem->EvaluateBounds (*(theUserDraw->Bounds));

return aElem;

Everything goes fine until returns... Checking in debug mode, "aElem" contains an "OpenGl_Element" and "myHandler" atributes but in my code, myHandler is correctly initialized but OpenGl_Element is nothing; in debug mode says: "this secondary value (OpenGl_Element) cannot be evaluated".

I don't know what I am doing wrong and I am a bit lost right now. My code is in a DLL and I can draw igs shapes and detect voxels with the mouse cursor in a panel without problems, only drawing voxels is failing in my project.
(I am using c++ and visual studio 2008).

Please let me know if you need more information.

Pawel's picture

Hello Julio,

from your description it's hard to say why the problem occurs but my guess is that the VoxelClient_VisDrawer is not correctly initialized.


Julio Alberto's picture


It seems you are right, I have just checked it. The value of myGraphicDriver, in my proyect, lacks one value that is present in the same variable in voxeldemo: "__vfptr" and that atribute is also missing in aElem.

I will check where is the problem in my code.

Julio Alberto's picture

Still no luck.

I have seen that, in mi code, the attribute "entity" (Handle_Standard_Transient) of myGraphicDriver is different in comparison with the same attribute in voxeldemo sample. Is that normal or should they be equal?

Pawel's picture

maybe you create a new 'myGraphicDriver' when initializing the voxel viewer instead of using the existing one...


Julio Alberto's picture

I use the same for my proyect :)
This is a bit of my code that initializes the viewer and voxel viewer (all of this is in the same .cpp):

Some declarations could be missing here, but they are in my code and everything compiles well.

Handle_V3d_Viewer myViewer;
Handle(V3d_View) myView;
Handle(AIS_InteractiveContext) myAISContext;
Handle_OpenGl_GraphicDriver myGraphicDriver;
static Handle(Graphic3d_GraphicDriver) Viewer_aGraphicDriver;

bool OCCViewer::InitViewer(void * wnd)
if (myGraphicDriver.IsNull())
if (Viewer_aGraphicDriver.IsNull())
Handle (Aspect_DisplayConnection) aDisplayConnection;
Viewer_aGraphicDriver = Graphic3d::InitGraphicDriver (aDisplayConnection);

myGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast(Viewer_aGraphicDriver);


TCollection_ExtendedString a3DName("Visu3D");
myViewer = new V3d_Viewer (myGraphicDriver, a3DName.ToExtString(),"", 1000.0,
V3d_XposYnegZpos, Quantity_NOC_BLACK,
Standard_True, Standard_False);


myView = myViewer->CreateView();
myAISContext = new AIS_InteractiveContext(myViewer);

Handle(WNT_Window) hWnd = new WNT_Window (reinterpret_cast (wnd));



myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_BLACK, 0.1, V3d_ZBUFFER);

return true;

And for initialization:

I think that everything is correct, isn't it?


Pawel's picture

Indeed, it looks OK.

Well, the problems seems to be somewhere else ;)


Julio Alberto's picture

Yes and that is bad for me hehe.

I have managed to catch the runtime error, and the exception says:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

I am going to see whats happening.

Julio Alberto's picture

Very good news. I have solved the problem.

It was memory allocation problem with tbb... I was using the 3º party tools dlls in the same directory of my proyet (I copied and pasted them) but now I set the PATH variable with the location of that dlls and it is working fine.