Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debug Assertion Failure in Wincore.cpp

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
0
0
US
Hi,
To retrieve data from my edit box, I decided to add a member function to my dialog's class, viz:
Code:
double CKuchukDlg::getrw(double x)
{
	//Get Data from the edit box
	CString strx;

	GetDlgItemText(IDC_WELLRAD,strx);
	x = atof(strx);
	
	return x;
}

i then used the function in my math function, to get the value of the edit box:
Code:
	void bessk0(double *x,double *k0,int nSize);
	void bessk1(double *x,double *k1, int nSize);
	void ei(double *x, double *expi, int nSize);

void unbound(double *unbd, int nSize)
{
	enum{nSize = 100};
	double A[nSize],B[nSize],k0[nSize],k1[nSize],s[nSize],expi[nSize],a[nSize],b[nSize];
	
	
	double x=0;
	s[0] = 1;
	a[0] = x*sqrt(s[0]);
	b[0] = 2*sqrt(s[0]);

	bessk0(a,k0,nSize);
	bessk1(a,k1,nSize);
	ei(b,expi,nSize);

	A[0] = k0[0]/(x*sqrt(s[0])*k1[0]);
	B[0] = (1-exp(-2*sqrt(s[0])))/(2*sqrt(s[0]));
	
	unbd[0]=0.5*(A[0]-B[0]-expi[0]);

	//double CKuchukDlg::getrw(double x);
	//x = getrw(x);
	
	CKuchukDlg MyClass;
	MyClass.getrw(x);
	x = MyClass.getrw(x);

	//trial: K0(x) --> x = rw*sqrt(s), as per A-32
	for (int t=1;t<nSize;t++)
	{

		s[t] = 2*t*PI;
		a[t] = x*sqrt(s[t]);
		b[t] = 2*sqrt(s[t]);

		bessk0(a,k0,nSize);
		bessk1(a,k1,nSize);
		ei(b,expi,nSize);

		A[t] = k0[t]/(x*sqrt(s[t])*k1[t]);
		B[t] = (1-exp(-2*sqrt(s[t])))/(2*sqrt(s[t]));
	
		unbd[t]=0.5*(A[t]-B[t]-expi[t]);
	}
}

While the code compiles without error, i still obtain a debug assertion failure in wincore.cpp!!

Is there a better way of calling my getrw(double x) in my math fxn without having this problem?

Thank you.
 
Look at what the assertion is telling you.

It's telling you that you've made a fundamental error in your program, and that further progress is not possible.

> sqrt(s[0]);
One such assert which could be possible is trapping the attempt to square root a negative number.

> GetDlgItemText(IDC_WELLRAD,strx);
> x = atof(strx);
Well atof() takes a char*, not whatever a CString is. First thing you need is to figure out how to convert from one to the other before calling atof().
Also, your parameter to this function is useless.

--
 
Thank you, Salem.
s[0] was already initialized to 1.
I changed
Code:
x = atof(strx);
to
Code:
x = atof((LPCTSTR)strx);
and you are right about the parameter; but the following modifications still resulted in the same error...
Code:
double CKuchukDlg::getrw()
{
	//Get Data from the edit boxes
	CString strx;
	double x;

	GetDlgItemText(IDC_WELLRAD,strx);
	x = atof((LPCTSTR)strx);
	
	return x;
}
Code:
	void bessk0(double *x,double *k0,int nSize);
	void bessk1(double *x,double *k1, int nSize);
	void ei(double *x, double *expi, int nSize);

void unbound(double *unbd, int nSize)
{
	enum{nSize = 100};
	double A[nSize],B[nSize],k0[nSize],k1[nSize],s[nSize],expi[nSize],a[nSize],b[nSize];
	
	
	double x=0;
	s[0] = 1;
	a[0] = x*sqrt(s[0]);
	b[0] = 2*sqrt(s[0]);

	bessk0(a,k0,nSize);
	bessk1(a,k1,nSize);
	ei(b,expi,nSize);

	A[0] = k0[0]/(x*sqrt(s[0])*k1[0]);
	B[0] = (1-exp(-2*sqrt(s[0])))/(2*sqrt(s[0]));
	
	unbd[0]=0.5*(A[0]-B[0]-expi[0]);

	//double CKuchukDlg::getrw(double x);
	//x = getrw(x);
	
	CKuchukDlg MyClass;
	MyClass.getrw();
	x = MyClass.getrw();

	//trial: K0(x) --> x = rw*sqrt(s), as per A-32
	for (int t=1;t<nSize;t++)
	{
			

		s[t] = 2*t*PI;
		a[t] = x*sqrt(s[t]);
		b[t] = 2*sqrt(s[t]);

		bessk0(a,k0,nSize);
		bessk1(a,k1,nSize);
		ei(b,expi,nSize);

		A[t] = k0[t]/(x*sqrt(s[t])*k1[t]);
		B[t] = (1-exp(-2*sqrt(s[t])))/(2*sqrt(s[t]));
	
		unbd[t]=0.5*(A[t]-B[t]-expi[t]);
	}
}
the debug assertion failure was at line ***, in C:\...\MFC\SRC\WINCORE.CPP, viz:
Code:
		HWND hWnd = ::GetDlgItem(m_hWnd, nID);
		if (hWnd != NULL)
		{
			int nLen = ::GetWindowTextLength(hWnd);
			::GetWindowText(hWnd, rString.GetBufferSetLength(nLen), nLen+1);//***
			rString.ReleaseBuffer();
		}

 
CString has an implicit LPCTSTR operator, so you don't need to explicitly cast it. Some people say this is a bad programming procedure, and sometimes it is, but it makes using MFC a lot easier when you don't have to worry about this kind of cast since you use it a lot.

When you get a problem like this, your best bet is to comment out a massive chunk of your code and try running it again. If it still doesn't work, comment out even more, and keep doing it until the program doesn't crash. Once it's stable, look at the last thing you commented out, because that has to have the problem in it. Uncomment lines a few at a time until you can tell specifically what line is causing you problems. You can generally figure out the problem from there, but if you can't, post again with the specific problem, giving details about what the values of the different variables are at this point.

Now that I've said that, I'll actually look at your code :). You should know that GetDlgItemText() only works for a dialog that is currently created. Unless CKuchukDlg calls DoModal() or Create() in the constructor, which is a poor design and not likely, this is the problem. You'll need to call DoModal() before calling getrw(), or if the dialog has already been created elsewhere (as implied since you say the user has already changed the edit box), get a pointer to that dialog object and call it's getrw() method. I don't know the architecture of your program, but these math functions should probably be members of some class, such as your dialog class so you could just call getrw() instead of needing a pointer to the dialog (the pointer would be "this").
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top