Hello,
I am having trouble with an access violation writing location 0xfeeefeee when I close my program.
I realize that I am having a common problem from my searches on Google, but I couldn't find anything that quite applies to my specific issue.
I am running this code in a separate thread from the main program thread, called by AfxBeginThread().
Code:
UINT CreateFilters(LPVOID v_Info) {
	CreateFiltersInfo* createInfo=(CreateFiltersInfo*)v_Info;
	HWND statusBar=createInfo->statusBar;
	float width=createInfo->width;
	int* percentDone=createInfo->percentDone;
	
	int number_of_filters=MAX_BPM-MIN_BPM+1;
	BPMFilters=new BPMFilter[number_of_filters];
	for (int i=0; i<number_of_filters; ++i) {
		 if (!BPMFilters[i].set(i+MIN_BPM, width,  5*sampleRate)) {
			return 0;
		}
		*(percentDone)=i;
	}
	return 1;
}
BPMFilter::set() reads as follows.
Code:
int BPMFilter::set(int sb, float sw, unsigned int sl) {
	BPM=sb;
	w=sw*sampleRate;
	length=sl;
	
	float B=TWOPI*(float)BPM/BASE_BPM_SAMPLES; // 2PI/B = Period
	float temp=cos(B*w/2.f);
	
	float A=temp/(1.f-temp); // Amplitude
	float C=A++; // Vertical shift. (Note: C is set to A's original value, THEN A is incremented by 1)
	
	if (a) delete [] a;
	a=new float[length];
	for (unsigned int i=0; i<length; i++) {
//these		a[i]=abs(A*cos(B*(float)i));
//lines		a[i]=(a[i]-C<0.f)?0.f:a[i]-C;
	}
	return 1;
}
The error occurs at the lines marked with comments. My issue is that even though my destructor deletes a[] and sets it to NULL and I tried a NULL check, the array seems to be set to 0xfeeefeee by HeapFree() (maybe?) when the program closes, causing the program to crash.
So, I am wondering what the best solution would be. Doing an IsBadReadPtr() check? Closing the thread from within itself when the program closes? Any help would be appreciated, thank you in advance.