I am performing a function that calculates the number of zones grouped into an array of pixels in a CCD.
The point is that the function sometimes gives an error "segmentation fault" and sometimes not. But always correct results in the last "cout". This is very strange because the same values with the function aborts and sometimes not, but always get a correct result for the number of zones. Also when I run the entire program slowly, the program works well Why is this? How I can fix it?
I know what is "segmetation fault", the function is designed to not access reserved memory areas, and I used a debbuger, and this is even more curious, because when I use debbuger never gives segmentation fault error and function runs perfectly.
Informatics someone can help a Spanish physicist? im running CodeBlocks in Ubuntu
When i == X-1, CCD[i+1] access memory that you have no business accessing when j is Y-1. Just accessing this memory is theoretically enough to cause a segmentation fault, but it is more likely caused by the accompanying else body.
Note that the if statement above will always return false when i is equal to X-1, because of the last condition in the if
The else:
else CCD[i+1][j].pas=true;
You have written to memory which you should not be accessing, and sooner or later it will cause problems.
I use this one specific case as an example, but the problem persists in many places within your code.