DiscussionsIssue archiveDraw Harness and Samples

Archived discussion

Run the sample in the user guides on the VS2019, but ALWAYS get exception.

Draw Harness and SamplesTue, 03/29/2022 - 11:542 replies

Browse this forum
QuestionAuthor

some talking before

Hi, guys!

Glad you have seen this post!

I'm really new to the OCCT, and I get a problem.

I am learning the OCCT, and I try to run the sample code in my PC.

Tried , failed , sad.

Could anyone help me with this annoying issue?

main context

Here's my code, its almost the same as the sample code (whose path is user guides -> visualization -> A Basic Example: How to display a 3D object

#include <Standard.hxx>
#include <Standard_Handle.hxx>
#include <V3d_View.hxx>
#include <AIS_InteractiveContext.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <TopoDS_Solid.hxx>
#include <AIS_Shape.hxx>

#include <iostream>


using namespace std;

int main()
{
    Handle(V3d_Viewer) theViewer;
    Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(theViewer);
    BRepPrimAPI_MakeBox abox(1,1,1);
    TopoDS_Solid aShape = abox.Solid();
    Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape); // creation of the presentable object
    aContext->Display(aShapePrs, AIS_Shaded, 0, true);   // display the presentable object and redraw 3d viewer

    return 0;
}
ENV

and I think I've done the setting, linked the dll and lib , included the headfiles.

the IDE is VS2019 , debug , x64.

Exception detail

Every time I run the code , VS thorw an exception:

Exception thrown: read access violation

theHandle is 0x18.

however, I can't find the reason through the code. I think there must be something wrong about these two lines. ( the first two line in the main() func )

  Handle(V3d_Viewer) theViewer;
  Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(theViewer);

If anyone has met the issue or know how to debug it , and is willing to tell me , I'll appreciate a lot!

Discussion

2 archived replies

Posts are displayed in their archived order.

01Commenter-1

You pass NULL object to the context, so that access violation is expected here:

  Handle(V3d_Viewer) theViewer;
  Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(theViewer);

The viewer setup requires more steps like creation of V3d_Viewer, graphic driver, native window and a view. Try starting from some existing sample (choose the one that better suites your needs / uses familiar GUI framework).

02Author

**My bad!**
So damn **new** to the GUI!
I see, so that's the problem.
I thought it was just as easy as read a STEP file using OCCT.

So much thanks for your time and reply! K.G!
Best wishes from the sincerely Alex!