Pass V3D_View to the other class

Hellow,

I am trying to use V3d in my own calss in MFC, but I have problem to pass the view.

can anyone tell me how should I do it?

I did this
CmyClss::aFounction()
{
Cmy3dView* aView;
aView->GetView(); aView->SetProj(V3d_Xneg);
}

Thanks You

QbProg's picture

Of course it crashes, your are dereferencing an uninitialized pointer. You can not do aView->GetView() if you don't set aView.

can you give some more code?

Tom Smith's picture

Hi Thomas,

that was the actually code. I have tried to get the GetView() Function in Cmy3DView Class to return the current Handle (V3d_View), which is an inline function that was coded as

public:
Handle(V3d_View)& GetView() { return myView;};

in the CMy3DView.h.

Could you be so kind to tell me how should I get it to return correctly?

Thanks fro your help

QbProg's picture

If you just use that code, the problem is not inside the member function, but inside the code:

Cmy3dView* aView;
aView->GetView(); <---------Creashed here
aView->SetProj(V3d_Xneg);
}
Of course it crashes , becase you are using an unitialized pointer.
This code doesn't make any sense. If you want to get a V3D_View from your Cmy3dView you should:
1) Get the active instance of Cmy3dView (i don't know MFC )
2) Get the view.
Something like

Cmy3dView * aView = .... get the active Cmy3dview from the application object
Handle(V3d_View) myView = aView->GetView ();
myView->SetProjection (..);

this code will crash on line 2 if you don't get propertly the object from line 1.