SF2SearchEx Access Violation when passing in image co-ordinates

Hello,

We have been having random crashes when running the SF2SearchEx function. We use this for character recognition so we loop around this function x10 passing in each character model. We know the area of where these characters are located so we set the (Left, Top, Right, Bottom) image co-ordinates.

Although not the actual code we use on our system I have managed to make a quick test function to prove the fault. All the models are the same and the image is also the same each time I have made it so the search area changes each time but I can get it to happen very quickly on a fixed area.

See below the function I have created to force this fault using these fixed Co-Ordinate variables,

I am using Windows 10, Stemmer Version V13.04.000 (32 bit).

It can happen after a couple of cycles.

Model’s and Image Link:
SF Models

SF sf[10];
IMG sfIMG;
CString Filepath

Filepath.Format(_T("C:\\TMS\\SFModels\\Test.png"));
LoadImageFile(CT2A(Filepath), sfIMG);

for(int Item = 0; Item < 10; Item++)
{
  Filepath.Format(_T("C:\\TMS\\SFModels\\%d.sf2"), Item);
   LoadSF(sf[Item], CT2A(Filepath));
}

cvbdim_t X1 = 550;
cvbdim_t Y1 = 137;
cvbdim_t X2 = 863;	
cvbdim_t Y2 = 300;

TSFSolution solution;
int CycleCount = 0

// Search on the through all the models in the system
do
{
  for(int Item = 0; Item < 10; Item++)
  {
    if(IsSF2(sf[Item]))
    {
      PIXELLIST solutions = NULL;
				
      // Fix value search each time
      if(SF2SearchEx(sf[Item], sfIMG, 0, X1, Y1, X2, Y2, SP_TolerantModel, solutions))
      {
        if(PixelListCount(solutions))
        {
          for(int k = 0; k < PixelListCount(solutions); k++)
            ListPixelEx(solutions, k, (double*)&solution);
        }
      }
      ReleaseObject(solutions);
    }
  }
  CycleCount++;
}	while(true);

I can pinpoint exactly how to get this fault

When create a array of SF objects. (In this case 10) and pass in image Co-ordinates you get a access violation:

The other test I have run (over 100,000 cycles each) and this fault does not occur are

  1. Single SF object maximum image co-ordinates
  2. Single SF object and apply random image co-ordinates each time (With the image size)
  3. Array of SF Objects and maximum image co-ordinates

I can provide code for a simple command line app that I have been running this test on.

I am initialising the array as follows:

SF sf[10]

for (int Item = 0; Item < 10; Item++)
  LoadSF(sf[Item], Format("C:\\sfTest\\%d.sf2", Item));

Hi @Austin

Thank you very much for the concise description, that was very helpful! I can confirm what you describe and I already have an idea what the reason is. If my assumptions turn out to be correct then I think I’ll be able to provide a fix early next week.

Hi @Austin

I will have a new build for you on Monday. The problem is now understood and has to do with the fact that the AOI is extending beyond the bottom edge of the image (image height is 300 - highest acceptable value for bottom is therefore 299) and will only occur if the search is limited to an AOI (as opposed to searching in the entire image). Of course this kind of situation must be handled gracefully, but due to a misconception in the creation of the internally used accumulator and a rounding effect the access does in fact touch unallocated memory, which gives rise to the access violation you saw.

Luckily the fix was not too complicated (correct the malformed generation of the accumulator so that it is robust versus the aforementioned rounding effect). As soon as the fixed version has passed the build and test farm I’ll post it here.

Here we go:

This should fix the problem you’ve reported.

@illusive

Thanks for the quick update on this, I have ran it through thousands of cycles on the test app I create and it has not faulted.

We are using this update on version 13.03.002 due to the problems with different user accounts.

https://forum.commonvisionblox.com/t/problems-opening-genicam-vin-driver-in-different-user-accounts/1454?u=austin

1 Like

Thanks @Austin for the feedback. The SF.dll I posted will work with practially any CVB version down to 13.0.