1

I'm trying to do a program that creates various filters through webcam feed and ran into some issues with BLOB-analysis and some other.

I'm getting segFault everytime I activate my grassfire function. Here's the code for my grassfire function:

void testApp::grassFire(int mask_Y, int mask_X, unsigned char labelCnt)
{
    blobArray[mask_Y * camWidth + mask_X] = labelCnt;
    if (mask_X + 1 <= camWidth - 1 && blobArray[mask_Y * camWidth + mask_X + 1] == 0)
       grassFire(mask_Y, mask_X + 1, labelCnt);
    if (mask_Y + 1 <= camHeight - 1 && blobArray[(mask_Y + 1) * camWidth + mask_X] == 0)
       grassFire(mask_Y + 1, mask_X, labelCnt);
    if (mask_X - 1 >= 0 && blobArray[mask_Y * camWidth + mask_X - 1] == 0)
       grassFire(mask_Y, mask_X - 1, labelCnt);
    if (mask_Y - 1 >= 0 && blobArray[(mask_Y - 1) * camWidth + mask_X] == 0)
       grassFire(mask_Y - 1, mask_X, labelCnt);
}

And how it is called is by a switch case that runs every frame This means it gets called every frame update

The function itself is declared outside any other scope.

I know it is a really heavy filter and it might be using a lot of memory, but compared to some of the other filters, it's not that bad, so I cannot figure out why i get the segFault.

I also get the segFault on another filter, that shouldn't be that memory usage demanding. I'm using openframeworks in codeblocks on win 7.

cmc
  • 2,061
  • 1
  • 19
  • 18
Jellezilla
  • 3,950
  • 1
  • 15
  • 15

3 Answers3

2

It doesn't look like you can read/write paste the end of your blobArray since you do some checking, so it means you're the victim of a stack overflow.

You should use a debugger and run a backtrace, that many calls cannot hide.

cmc
  • 2,061
  • 1
  • 19
  • 18
0

If you have a lot of array values of 0, you're probably getting a stack overflow due to the heavily recursive nature of the function. I'd suggest trying an iterative flood fill algorithm instead and see if that fixes the problem.

Community
  • 1
  • 1
Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
0

I would instrument the application with valgrind. Valgrind will show a stack trace of where the segmentation fault occurred.

Vandhunden
  • 426
  • 4
  • 11