-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Inconsistent handling of value argument in createTrackbar. #20159
Copy link
Copy link
Closed
Labels
Milestone
Description
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:
- Win32 -- https://github.com/opencv/opencv/blame/master/modules/highgui/src/window_w32.cpp#L2368
- GTK -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_gtk.cpp#L1421
- Cocoa -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_cocoa.mm#L949
Some consider it an error:
- Qt -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_QT.cpp#L1222 (invoked from https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_QT.cpp#L605)
And some apparently dereference it without even checking:
- WINRT -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_winrt_bridge.cpp#L274 (invoked from https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_winrt.cpp#L115)
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
Reactions are currently unavailable