Ask Your Question
0

Destroying Windows in Separate Functions

asked Mar 26 '13

amaharajh gravatar image

updated Mar 26 '13

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;
}
Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Mar 26 '13

Seb gravatar image

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

Preview: (hide)

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 (Mar 26 '13)edit

Question Tools

1 follower

Stats

Asked: Mar 26 '13

Seen: 512 times

Last updated: Mar 26 '13