Ask Your Question
0

Destroying Windows in Separate Functions

asked 2013-03-26 13:36:15 -0600

amaharajh gravatar image

updated 2013-03-26 14:16:20 -0600

Hi everyone,

This may seem like a newbie question but I hope I can get some assistance with this problem I'm having.

I have an initialize function that sets up my cvCapture object to start capturing from a video file named initialize(). The cvCapture object named capture is created as a global variable just for testing purposes.

I have one function that creates three windows named A,B and C and this function does some processing with the windows showing their progress. Let's call this function runProcessing()

I want to destroy windows A,B and C in a separate function named releaseMemory() after runProcessing() has executed. However, when I try to call cvDestroyWindow() or cvDestroyAllWindows(), the program freezes and does not terminate correctly.

How do I go about destroying the windows properly seeing that they are created in another function instance in order to correctly exit my program?

Example source code:

int intialize(){
  ......
  capture = cvCreateFileCapture(filename);
  ......
}

int runProcessing(){
  ......
  cvNamedWindow("A", 1);
  cvNamedWindow("B", 2);
  cvNamedWindow("C", 3);
  ........
}

void releaseMemory(){
  cvReleaseCapture(&capture);
  cvDestroyWindow("A");
  cvDestroyWindow("B");
  cvDestroyWindow("C");
}

int main(){
  initialize();
  for(;;){
    runProcessing();
  }
  releaseMemory();
  return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-03-26 14:02:24 -0600

Seb gravatar image

First thing first, did you break into your code and are you 100% sure that you program freeze at the cvDestroyWindow?

edit flag offensive delete link more

Comments

Ahhh, so silly of me. I forgot to return an exit code from runProcessing() and check the exit code to break the for loop. Thank you for the assistance.

amaharajh gravatar imageamaharajh ( 2013-03-26 14:17:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-03-26 13:36:15 -0600

Seen: 417 times

Last updated: Mar 26 '13