TKV3d.dll Access Violation Error.

#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include <BRepPrimAPI_MakeWedge.hxx>
#include <AIS_Shape.hxx>

int main() {

Standard_Real theWedgeDX = 30;
Standard_Real theWedgeDY = 15;
Standard_Real theWedgeDZ = 10;
Standard_Real theWedgeLtx = 5;

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

BRepPrimAPI_MakeWedge aWedgeMaker(theWedgeDX, theWedgeDY, theWedgeDZ, theWedgeLtx);
TopoDS_Solid aShape = aWedgeMaker.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;
}

Error Details :
Unhandled exception at 0x00007FFD620331B0 (TKV3d.dll) in OpenCascade.exe: 0xC0000005: Access violation reading location 0x0000000000000018.

I am a beginner. Please clarify what i am doing wrong here.

Dmitrii Pasukhin's picture

Hello, the issue, that your 'theViewer' is nullptr. You need to initialize viewer with platform depended code.

// create a default display connection
Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
// create a Graphic Driver
Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDispConnection);
// create a Viewer to this Driver
Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver);

Best regardsm Dmitrii.

Purushothaman Munusamy's picture

Thank you so much for your help again.

#include
#include
#include
#include
#include
#include
#include

int main() {

Standard_Real theWedgeDX = 30;
Standard_Real theWedgeDY = 15;
Standard_Real theWedgeDZ = 10;
Standard_Real theWedgeLtx = 5;

// create a default display connection
Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();

// create a Graphic Driver
Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver(aDispConnection);

// create a Viewer to this Driver
Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);

// To manage graphic behaviour including selection
Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(aViewer);

// creation of wedge.
BRepPrimAPI_MakeWedge aWedgeMaker(theWedgeDX, theWedgeDY, theWedgeDZ, theWedgeLtx);
TopoDS_Solid aShape = aWedgeMaker.Solid();

// creation of the presentable object
Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);

// display the presentable object and redraw 3d viewer
aContext->Display(aShapePrs, AIS_Shaded, 0, true);

return 0;
}

I updated the code with your response. there are no errors i believe.

still there is no screen with a wedge. I am using this link to create screen https://dev.opencascade.org/doc/overview/html/occt_user_guides__visualization.html#occt_visu_2_1_3

gkv311 n's picture

You need also creating V3d_View and map it to a window (Aspect_Windowsubclass depending on your system)

Purushothaman Munusamy's picture

Thank you. i changed the code to look like this.

#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include <BRepPrimAPI_MakeWedge.hxx>
#include <AIS_Shape.hxx>
#include <Aspect_DisplayConnection.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <WNT_Window.hxx>
#include <WNT_WClass.hxx>
#include <V3d_View.hxx>

int main() {

	Standard_Real theWedgeDX = 30;
	Standard_Real theWedgeDY = 15;
	Standard_Real theWedgeDZ = 10;
	Standard_Real theWedgeLtx = 5;

	// create a default display connection
	Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
	// create a Graphic Driver
	Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver(aDispConnection);

	// create a Viewer to this Driver
	Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);
	aViewer->SetDefaultLights();
	aViewer->SetLightOn();

	// Creating a view for WNT_Window
	Handle(V3d_View) aView = new V3d_View(aViewer);

	// Creating WNT Class for WNT window
	Handle(WNT_WClass) aWinClass = new WNT_WClass("My Class", nullptr, 0);

	// Creating WNT window
	Handle(WNT_Window) aWindow = new WNT_Window("My Window", aWinClass, 100, 100, 512, 512, Quantity_NOC_BLACK);

	aView->SetImmediateUpdate(false);
	aView->SetShadingModel(Graphic3d_TOSM_FRAGMENT);
	Handle(Aspect_Window) theWindow;
	aView->SetWindow(aWindow);
	aView->SetBackgroundColor(Quantity_NOC_GRAY50);
	aView->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
	aView->TriedronDisplay();

	// To manage graphic behaviour including selection
	Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(aViewer);

	// creation of wedge.
	BRepPrimAPI_MakeWedge aWedgeMaker(theWedgeDX, theWedgeDY, theWedgeDZ, theWedgeLtx);
	TopoDS_Solid aShape = aWedgeMaker.Solid();

	// creation of the presentable object
	Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape); 

	// display the presentable object and redraw 3d viewer
	aContext->Display(aShapePrs, AIS_Shaded, 0, true);   

	return 0;
}

and i still get this error.

Unhandled exception at 0x00007FFB5DAEFE4C in OpenCascade.exe: Microsoft C++ exception: Aspect_WindowDefinitionError at memory location 0x0000009D4A4FEF88.

Dmitrii Pasukhin's picture

Please check all Handle for initial value.

For example: Handle(Aspect_Window) theWindow;

Best regards, Dmitrii.

gkv311 n's picture

While copy-pasting code snippets from documentation, pay attention to theSomething = ... at the beginning of snippet - this is a placeholder for an object, initialized somewhere else. You're passing NULL pointer to functions a couple of times in your code.

Consider also building some existing working sample project as alternative to writing a sample from code fragments without trying to read the logic behind these snippets.

Purushothaman Munusamy's picture

I am sorry. I am just trying to build one working file. so that i can breakthrough it.

Thank you.

Dmitrii Pasukhin's picture

The best option to check the issues during starting - build in debug mode with debug info. It will help you to investigate new tool by code analysis.

As for a first sample, indeed in the documentation have no = ...; that can lead to misunderstanding. We need to check that, I will try to plan that.

So, my recommendation - build OCCT in debug mode and check the exceptions base on stack and code details ;)

Best regards, Dmitrii.

Purushothaman Munusamy's picture

Sure. Thank you.

I will improve myself and comeback soon with questions if any.