Sign in to follow this  

assertion error

This topic is 3633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
	}
..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 3633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this