assertion error

Started by
3 comments, last by jagguy2 16 years, 3 months ago
i cant move my code to a class that simply prints out a mouse location. It works fine in main program but not in a class. I get an assertion run-time error to do with lines marked below

in .h file 

void userInput(LPDIRECT3DDEVICE9,HWND);
POINT pt;
RECT font_rect2;
wchar_t *fps1,*fps2;


//declare in constructor

font_rect2.left  =0;
font_rect2.top  =0;
font_rect2.right  =300;
font_rect2.bottom =25;
fps1=NULL;
//

// this code will get an assertion error but will work if i dont get
 the cursor position. i pass the HWND variable so is this a problem?

//the code will work if not in a class


//member function 
void camera::userInput(LPDIRECT3DDEVICE9     g_pd3dDevice,HWND g_hWnd)
{
if (GetAsyncKeyState(VK_LBUTTON))
	{
		
		GetCursorPos(&pt); //error with this 
	    ScreenToClient(g_hWnd, &pt);	//or error with this

		swprintf(fps1,L"%ld",pt.x);
	//fps1=L"Greetings "; //will work with this code
		g_font->DrawText(NULL, fps1, -1, &font_rect2,
					DT_LEFT|DT_TOP,   0xffffffff);
	}
..
Advertisement
the problem is this after i debug

wchar_t *fps1; //this fails
wchar_t fps1[20]; //this works




swprintf(fps1,L"%ld",pt.x);
Do you allocate memory for the fps1 character array?

Also, while some people here might be able to tell you the exact error, you are much less likely to run into these kinds of problems if you stop using character arrays and start using std::string (or std::wstring) in conjunction with string streams.
In my constructor I use these declarations and i get errors i dont understand

//RECT font_rect2={0,0,300,25}; //this gets an error why?
font_rect2.left =0;
font_rect2.top =0;
font_rect2.right =300;
font_rect2.bottom =25;
pt=NULL;//fails
pt=0;/fails
pt.x=0;
pt.y =0;
fps1 = new wchar_t;//works but why use wstring?
in the .h OR constructor i get an error as this is a const

RECT font_rect2(0,0,300,25); //error
or
RECT font_rect2=(0,0,300,25);//error

This topic is closed to new replies.

Advertisement