Skip to content

Inconsistent handling of value argument in createTrackbar. #20159

@dan-masek

Description

@dan-masek

Verified in code of master branch, IMHO relevant to most current releases.

According to the documentation of createTrackbar the third parameter to the function is an "Optional pointer to an integer". I read that as "you can pass a nullptr here".

Some HighGUI backends handle this scenario correctly:

Some consider it an error:

And some apparently dereference it without even checking:


Code that should reproduce this (works on Windows, don't have means to test other backends):

#include <opencv2/opencv.hpp>

void on_trackbar(int pos, void* userdata)
{
}

int main()
{
    auto window_name("Test Window");
    cv::namedWindow(window_name);

    cv::createTrackbar("Trackbar", window_name, nullptr, 100, on_trackbar);

    cv::Mat temp = cv::Mat::zeros(256, 256, CV_8UC1);
    cv::imshow(window_name, temp);

    cv::waitKey();
    return 0;
}

Reference: https://stackoverflow.com/q/67690257/3962537

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions