'Basler Pylon camera API

In the c++ documentation for the pylon API, they use a loop to display the grabbed images. This code works fine:

//Basler-Pylon example

main()
{

    CInstantCamera camera( 
    CTlFactory::GetInstance().CreateFirstDevice());
    camera.StartGrabbing( c_countOfImagesToGrab);
    while ( camera.IsGrabbing())
    {
        // Wait for an image and then retrieve it. A timeout of 
        5000 ms is used.
        camera.RetrieveResult( 5000, ptrGrabResult, 
        TimeoutHandling_ThrowException);
        Pylon::DisplayImage(1, ptrGrabResult);
    }

}

In my application I use the API by implementing a UseBasler class, it instantiates the camera in the constructor and then uses a function to display one frame at a time:

class UseBasler()
{
public: 
    CInstantCamera* camera;
    void DisplayOneFrame();

}


UseBasler::UseBasler()
{
    camera = new CInstantCamera(CTlFactory::GetInstance().CreateFirstDevice());
    camera->StartGrabbing( c_countOfImagesToGrab);

}


void UseBasler::DisplayOneFrame()
{
    if ( camera->IsGrabbing())
    {
        // Wait for an image and then retrieve it. A timeout of 5000 ms is used.

        camera->RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);

        //Display image
    }
}

I am getting Acces violation in the function DisplayFrame at the line

camera->RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);

I would appreciate input on why I am getting this crash. By the way when I move the call to the function RetrieveResult to the constrctor just after I create the camera, I don't get this crash.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source