Opencv 2.4.0 with QT 4.7.4 and cvcreatebutton exception (Bug #1890)


Added by marc w almost 5 years ago. Updated over 3 years ago.


Status:Done Start date:2012-05-03
Priority:Normal Due date:
Assignee:Alexander Smorkalov % Done:

0%

Category:highgui-gui
Target version:Next Hackathon
Affected version:2.4.6 (latest release) Operating System:Any
Difficulty: HW Platform:x86
Pull request:https://github.com/Itseez/opencv/pull/1459

Description

Hello

I have compiled opencv with qt and opengl flag. now many of qt functions from the documentation are working but not the cvcreatebutton. it throws an exception (e.g see screenshot) the example from the documentation dont work.. evertime i use cvcreatebutton it fails.

my code:

void callBackR(int state, void *pointer){
    printf("%d",state);
    return;
}

int main(){
....
cvCreateButton("test",callBackR);
...

}

Marc


Unbenannt.JPG - visual 2010 german screenshot exception while debug (64.6 kB) marc w, 2012-05-03 10:39 pm


History

Updated by Andrey Kamaev almost 5 years ago

  • Category set to highgui-images

Updated by Andrey Kamaev over 4 years ago

  • Category changed from highgui-images to highgui-gui

Updated by Tim Sweet over 3 years ago

Hello!

I've spent the last few hours tracking this bug down and finally went all the way back to the C interface source to figure it out. For context, here's the source of the old function cvCreateButton: https://github.com/Itseez/opencv/blob/e59c74e1c7672ad16056f32136a491b1e008e295/modules/highgui/src/window_QT.cpp#L603

On lines 605-606 if no gui has been drawn yet it should produce a CV_Error, however all I get is a segmentation fault. The segmentation fault is actually raised on lines 611-618 (see justification below). I'm not sure how to fix this because if I call CV_Error(CV_StsNullPtr, "NULL guiReceiver (please create a window)") directly I get the correct error and the program terminates correctly.

Steps to reproduce the bug:
- Using OpenCV 2.4 on Linux, compiled from source (not sure if it affects other versions)
- Before opening any OpenGL windows (but regular windows can be opened, such as cv::namedWindow("output",CV_WINDOW_AUTOSIZE) ) make a call to:

cv::createButton("Button",ButtonCallback); //where ButtonCallback is prototyped as void Foo(int,void*)

- Get segmentation fault
- This can be pinpointed to lines 611-618 in the source by calling cv::createButton("Button",ButtonCallback,NULL,CV_PUSH_BUTTON,-10) which will try to create a button with invalid initial state -10, causing the function to immediately return 0 and not segfault.

If someone points me in the right direction I'd be happy to produce a pull request to fix this, I'm just not sure how to go about it..

  • Assignee deleted (Alexander Reshetnikov)

Updated by Tim Sweet over 3 years ago

I should be more specific: something along these lines has to happen in order to not get the segmentation fault. If this doesn't happen the expected behavior is to throw a CV_Error:

  • cv::namedWindow("name",CV_WINDOW_OPENGL);
  • cv::Mat image(cv::Size(1,1),CV_8UC1,cv::Scalar(0)); //any initialized Mat will do
  • cv::imshow("name",image);

Updated by Anna Kogan over 3 years ago

Hello Tim, thank you for debugging the issue!

Alexander, could you please take a look at this?

  • HW Platform set to x86
  • Operating System set to Any
  • Affected version set to branch '2.4'
  • Assignee set to Alexander Smorkalov

Updated by Alexander Smorkalov over 3 years ago

You can contribute your fixes using the instruction from "How to contribute" wiki page: http://code.opencv.org/projects/opencv/wiki/How_to_contribute

Updated by Alexander Smorkalov over 3 years ago

  • Target version set to Next Hackathon

Updated by Alexander Smorkalov over 3 years ago

I reproduce the problem with small sample:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>

void callBackR(int state, void *);

void callBackR(int state, void *)
{
    printf("%d",state);
    return;
}

int main(int, char**)
{
    cv::namedWindow("qqq", CV_WINDOW_OPENGL);
    cv::createButton("Button", callBackR);
    cv::waitKey();
    return 0;
}

Application fails not here, but inside QVector. Problem is cased by window_QT.cpp:1739

void CvWindow::enablePropertiesButton()
{
    vect_QActions[9]->setDisabled(false);
}

Updated by Alexander Smorkalov over 3 years ago

  • Pull request set to https://github.com/Itseez/opencv/pull/1459

Updated by Alexander Smorkalov over 3 years ago

  • Status changed from Open to Done
  • Affected version changed from branch '2.4' to 2.4.6 (latest release)

Also available in: Atom PDF