Ask Your Question

Revision history [back]

Destroying Windows in Separate Functions

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(;;){
    runCodeBook();
  }
  releaseMemory();
  return 0;
}

Destroying Windows in Separate Functions

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(;;){
    runCodeBook();
runProcessing();
  }
  releaseMemory();
  return 0;
}