Problem with Header Allocation of Class fields
<p>Little bit of background, I'm more expereinced with Java, and have some C/C++ experience.<br>
Company wanted to do this in C++, so I wrote this.  I'm using Visual Studios 2010.  </p>

<p>I created two classes inside a header file and gave them fields.<br>
It compiles ok, and for the longest time it was running just fine.<br>
I copied the entire project directory to a new folder (all files inside) and simply recompiled and ran it.  Now whenever I run it I get "Unhandled exception at 0x637779ab in RegistrationExpLib2.exe: 0xC0000005: Access violation writing location 0x00000000." At this line  </p>

<pre><code>FourierTrans[i] = fftwf_plan_dft_2d(imgRows, imgCols, in[i], out[i], FFTW_FORWARD, FFTW_MEASURE);
</code></pre>

<p>I checked the debugger, and all of the class fields return could not evaluate expression.<br>
I've already checked and the image is being read in correctly.  And as far as I can tell All of the memory has been allocated correctly.  fftw3 is a C dll I'm linking against.<br>
So I'm really puzzled and was hoping someone could point out a possible issue.  I'm thinking its either, I'm doing something wrong with the set up when I copied the Visual Studios Project(Even though I didn't change anything since it was working), or I've incorrectly allocated memory in the header.  Another issue I thought of is each image is about 20MB, so I may be messing with the heap. 
I really appreciate any help.  </p>

<p>GlobalRegistration.h  </p>

<pre><code>#include"ComplexImageClassFFTW.h"
#include"fftw3.h"
#include"pthread.h"
#include"SemaphoreImplement.h"

#ifndef GLOBALREGISCLASS
#define GLOBALREGISCLASS

//At 8 it crashes frequently, and there is no time improvement.
#define NUMTHREADS 4

/*
* This class is designed to set up and allocate space for a number of registrations to occur simultaniously.
* It allocates and deallocates space, as well as returns a registration object, which will register an image with
* an input reference image, in relation to the mission image.  The register class is responsible for
* deallocating the memory created.
*/
class Register {

private:
   //The hight and width of the image.
   int imgRows,imgCols;
   //The mission images in the frequency and spatial domains.
   fftwf_complex* missionFreqDom;
   //The input and output 2d complex images.
   fftwf_complex** in;
   fftwf_complex** out;
   //The plan calculated for in and out.
   fftwf_plan FourierTrans[NUMTHREADS];
   fftwf_plan invFourierTrans[NUMTHREADS];

   //two arrays of ints used for interpolating.
   float* f1;
   float* f2;
   //Semaphore is used to indicate when done with a resource.
   semaphore resourceSem;

public:
   /**
   * This takes the mission image and calculates its fourier transform into the
   * frequency domain and sets it internally.
   */
   Register(ComplexImageFFTW &amp;mission);

   ~Register();
};  
</code></pre>

<p>Relevent Parts of GlobalRegistration.cpp  </p>

<pre><code>#include "ComplexImageClassFFTW.h"
#include "GlobalRegistration.h"
#include "fftw3.h"
#include &lt;stdio.h&gt;

#define TESTNUM 80

//A simple test main.
int main() {
   ComplexImageFFTW a;
   ComplexImageFFTW b[TESTNUM];
   ComplexImageFFTW* ptrB;
   ptrB = b;

   printf("start\n");
   a.readImage("C:\\Users\\wilsond\\Desktop\\Forensics\\GemData\\mission\\imagefile", true);
   printf("Mission\n");
   for(int i = 0; i &lt; TESTNUM; i++) {
          b[i].readImage("C:\\Users\\wilsond\\Desktop\\Forensics\\GemData\\reference\\imagefile", true);
   }
   Register gr(a);    
         ...
} //End main

/**
* This takes the mission image and calculates its fourier transform into the
* frequency domain and sets it internally.
*/
Register::Register(ComplexImageFFTW &amp;mission) {
   bool ret = InitSemaphore(resourceSem, NUMTHREADS);

   if(!ret) {
       printf("Failed making semaphore.\n");
   }

   //Gets the height and width.
   imgRows = mission.getHeightPixels();
   imgCols = mission.getWidthPixels();  

   //Sets the maximum allowable planning time to 30 seconds
   fftwf_set_timelimit(30);

   in = (fftwf_complex**) fftwf_malloc(sizeof(fftwf_complex*) * NUMTHREADS);
   out = (fftwf_complex**) fftwf_malloc(sizeof(fftwf_complex*) * NUMTHREADS);

   //Allocates space for in and out.
   for(int i = 0; i &lt; NUMTHREADS; i++) {
                    //Crashes here.
       in[i] = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * imgRows * imgCols);
       out[i] = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * imgRows * imgCols);
   }

   for(int i = 0; i &lt; NUMTHREADS; i++) {
       //Creates a complex plan for forward and inverse fourier transforms.
       FourierTrans[i] = fftwf_plan_dft_2d(imgRows, imgCols, in[i], out[i], FFTW_FORWARD, FFTW_MEASURE);
       invFourierTrans[i] = fftwf_plan_dft_2d(imgRows, imgCols, in[i], out[i], FFTW_BACKWARD, FFTW_MEASURE);
}
</code></pre>
