gnebehay/OpenTLD

Using OpenTLD in a Managed Application

Opened this issue · 1 comments

I have tried compiling OpenTLD as a dll and importing into a c# application. I am able to create and delete objects in the unmanaged dll from the managed application using pInvoke. But as after I create a pointer to Main the application will crash if I do any of the following:

  • Delete the Unmanaged object containing a pointer to Main
  • Run any of the main->tld-> functions
  • Even cvReleaseImage(&img); crashes the application

The message that I get is 'System.AccessViolationException' occurred - Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Has anyone used OpenTLD as a dll in a managed application? Are there any memory issues that I should be aware of?

Adding "nnClassifier = NULL;" in the destructor for TLD and removing the if code below fixed nearly all of the problems.
if(nnClassifier)
{
delete nnClassifier;
nnClassifier = NULL;
}
The nnClassifier was already cleaned out in detectorCascade.nnClassifier and since they were pointing to the same object it was trying to delete a second time. I placed the delete nnClassifier in DetectorCascade destructor in the above if block and set it to NULL.

The cVReleaseImage(&img) should not have been called in my code since I was feeding OpenTLD an IplImage struct from my c# application.

So I do have OpenTLD working as an imported unmanaged dll in by c# application. Please consider changing the destructor code for nnClassifier as I mentioned above. It took me a few days to find this since Visual studio does not let me debug an unmanaged dll from within a managed application. This will prevent application crash when OpenTLD is used as a dll.

Vinay Reddy