Sign in to follow this  

Error while compiling

This topic is 3292 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

Hey, hi again. I am coming with a new problem: I cannot execute a program. It contains a function (render) defined like this:
VOID Render()
{
	IDirect3DSurface9* surface;
	IDirect3DSurface9* backbuffer;
	int letterWidth=(478/7);
	int letterHeight=(478/7);
	int destx=48;
	int desty=96;
	char* message = "hello world";
	if (NULL==g_pd3dDevice)
		return;

	hResult=g_pd3dDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
	if (FAILED(hResult))
		return;
	hResult=D3DXLoadSurfaceFromFile(surface, NULL, NULL, "alphabet.bmp", NULL, D3DX_DEFAULT, 0, NULL);
	if (FAILED(hResult))
		return;
	
	//Clear the backbuffer to a blue color
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100, 200, 255), 1.0f, 0);

	//Get the backbuffer
	g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //Here we get a pointer to the backbuffer surface
	
	//Set up a counter variable to hold the letter position on the screen
	int count=0;

	//Loop through the message one character a time
	for (char* c = message; c!= " "; c++)
	{
		//source and destination rectangles
		RECT src;
		RECT dest;

		//Set the source rectangle
		int srcY = ( ( ( *c - 'A' ) / 6 ) ) * letterHeight;
		int srcX = ( ( ( *c - 'A' ) % 7 ) * letterWidth );
		src.top		=	srcY;
		src.left	=	srcX;
		src.right	=	src.left + letterWidth ;
		src.bottom	=	src.top  + letterHeight;

		//Set the dest rectangle
		dest.top		=	desty;
		dest.left		=	destx     + (letterWidth * count);
		dest.right		=	dest.left + letterWidth;
		dest.bottom		=	dest.top  + letterHeight;

		//Increase the letter count by one
		count++;
		[color=red]g_pd3dDevice->StretchRect(surface, src, backbuffer, dest, D3DTEXF_NONE);[/color]
	}

	//Present the backbuffer contents to the display
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
When I try to execute the code, I get an error when calling StretchRect method. The error says:
error C2664: 'IDirect3DDevice9::StretchRect' : cannot convert from parameter 2 'RECT' to 'const RECT *'
I don`t know how to handle this error, and I cannot go on programming without solving this problem... help, please. Thank you! Skinner

Share this post


Link to post
Share on other sites
JParishy, you got the reason, that was the mistake :P

But now, once compiled and executed, my window closes and I get an alert Message. It says: Exception no controlled in 0x0047f08b in AlphabetSurfacesDirect3D.exe: 0xC0000005: Access infraction to read the location 0x00597000.

And gives me two options: EXIT, or CONTINUE. It will surely be any back buffer or RAM problem. Do you know what that message error means? Can you help me, please?

Thank you!

Skinner

Share this post


Link to post
Share on other sites
Have you enabled the DirectX Debug Runtime, and consequently seen any debug messages outputted to the console in Visual Studio?

[EDIT]
Actually, what exactly are you trying to achieve? If you are trying to print out the string, which it looks like you are, you may what to consider a for-loop like:


for(int i = 0; i < strlen(message); ++i)
{
char currentChar = message[i];
// Do what you have to do with that char.
}


Share this post


Link to post
Share on other sites
Yes, I have a bitmap of 478px X 478px, with 7 columns and 7 rows. First 4 rows are filled out with the alphabet letters. What I am trying to achieve, is to "cut" letters I need to make up a phrase, or a word, or anything I wish, but it appears nothing to happen.

Help! Thank you,

Skinner

[EDIT]
How did you colorized and put your code with that black-bordered, white rectangle?? It is very easy to read, and I think it would help me for further codes!

Share this post


Link to post
Share on other sites
Quote:
Original post by darkcube
It doesn't work. The compiler says the error is within:

int srcY = ( ( ( *c - 'A' ) / 6 ) ) * letterHeight;

:S
Since the only pointer there is 'c', it's invalid somehow. It's likely you're reading off the end of the array, in which case _Kami_'s solution should work. Or, if you prefer:
for (char* c = message; c!= NULL && c!= ' '; c++)

Share this post


Link to post
Share on other sites

This topic is 3292 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