Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track bar callback throws exception #14

Open
SSteve opened this issue Nov 15, 2019 · 1 comment
Open

Track bar callback throws exception #14

SSteve opened this issue Nov 15, 2019 · 1 comment

Comments

@SSteve
Copy link
Contributor

SSteve commented Nov 15, 2019

I'm trying to write a sample to show how to use a track bar. I can create the track bar and display it in a window, but when I click on it I get this exception:

Managed Debugging Assistant 'InvalidVariant' has detected a problem in 'SamplesCS.exe'.
Additional Information: An invalid VARIANT was detected during a conversion from an unmanaged VARIANT to a managed object. Passing invalid VARIANTs to the CLR can cause unexpected exceptions, corruption or data loss.

I don't have experience with going back and forth between unmanaged and managed data. What should I do to avoid this exception?

Here's the code so far:

public class TrackBarSample : ISample
{
    public void Run()
    {
        using var src = Cv2.ImRead(FilePath.Image.Balloon);
        const string windowName = "TrackBar Sample";
        using var _ = new Window(windowName, WindowMode.Normal);
        var trackBarValue = 256;
        var trackBarRed = Cv2.CreateTrackbar("red", windowName, ref trackBarValue, 511, OnTrackBarChange);
        Cv2.ImShow(windowName, src);
        Cv2.WaitKey(0); 
    }

    private void OnTrackBarChange(int pos, object userData)
    {
        Debug.WriteLine($"track bar: {pos} object: {userData}");
    }
}
@dotoritos-kim
Copy link
Contributor

I'm going to pull request the Trackbar example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants