[vtkusers] error in callback

David Doria daviddoria+vtk at gmail.com
Mon May 17 07:31:10 EDT 2010


On Mon, May 17, 2010 at 7:20 AM, Jinyoung Hwang <hwangjinyoung at gmail.com> wrote:
> Hi folks,
>
> I'm testing callback function in VTK textbook as follows,
>
> void MyClass::KeypressCallbackFunction (vtkObject* obj, unsigned long,
> void*, void*)
> {
>  cout << "modified callback" << endl;
>  vtkRenderWindowInteractor *iren =
> static_cast<vtkRenderWindowInteractor*>(obj);
>  cout << "Pressed: " << iren->GetKeySym() << endl;
>  vtkRenderer *ren = reinterpret_cast<vtkRenderer*>(obj);
>   cout << ren->GetActiveCamera()->GetPosition()[0] << " "
>    << ren->GetActiveCamera()->GetPosition()[1] << " "
>    << ren->GetActiveCamera()->GetPosition()[2] << "\n";
> }
>
> But, I got an error message at second and third cout function.
>
> ---
> Unhandled exception in MyClass.exe: 0xC0000005: Access Violation.
> ---
>
> How to break the error?

Check if the cast worked

vtkRenderer *ren = reinterpret_cast<vtkRenderer*>(obj);
if(!ren) cout << "Cast didn't work!";

Thanks,

David



More information about the vtkusers mailing list