Sign in to follow this  
POLSKASH

Can't set RECT values?

Recommended Posts

I have RECT* srcRectBg; declared in the private scope of a class. In the constructor's implementation, I have srcRectBg->left = 0; and it gives me an access violation. What the crap?

Share this post


Link to post
Share on other sites
Hmm, I added srcRectBg = new Rectangle(0,0,0,640,480) above srcRectBg->left = 0;

Now I'm getting 100+ errors on the next piece of code in the exact same place?! This stuff compiled just fine before adding in the allocation.

Share this post


Link to post
Share on other sites
That does sound strange (your second post). Post some of your code. si it just that you wrote Rectungle instead of RECT?

One thing I would avoid is unnecessary use of memory allocation. Im almost 100% sure that you do NOT need to in your case.

Functions such as SetRect are misleading someitmes. They take a RECT* as a parameter, but that should not persuede you to declare your RECTS as pointers then allocate their memeory. Do this:

RECT rec;

SetRect( &rec,....);

Share this post


Link to post
Share on other sites
Rectangle? According to MSDN there's a Rectangle function at least but I can't find any matching type, especially not any inheriting from RECT.
If it really needs be allocated dynamically then shouldn't you allocate a RECT instead, and what's the fifth parameter supposed to do?

Share this post


Link to post
Share on other sites
Quote:
Original post by doynax
Rectangle? According to MSDN there's a Rectangle function at least but I can't find any matching type, especially not any inheriting from RECT.
If it really needs be allocated dynamically then shouldn't you allocate a RECT instead, and what's the fifth parameter supposed to do?


Damn it, i tried rating you up to 1337, but barely missed....

Share this post


Link to post
Share on other sites
sorry if im mistaken, but this is what your preceding posts tell about your code:

int myfunc
{
RECT* srcRectBg;
srcRectBg = new Rectangle(0,0,0,640,480);
}



isnt it supposed to be "srcRectBg = new RECT(...)" or sumthing like that?

Share this post


Link to post
Share on other sites
I don't think it's really necessary to dynamically allocated this structure. And, heh, I was calling Rectangle(HDC,left,...). It's not even related to what I'm doing. ;) I'm just gonna declare a RECT variable and not a pointer.

Share this post


Link to post
Share on other sites
Quote:
Original post by POLSKASH
And I get this error when doing srcRectBg = new RECT(0,0,640,480);
The RECT structure doesn't have any constructor. Try simply allocating it instead.
srcRectBg = new RECT;

Share this post


Link to post
Share on other sites
That worked doynax, thanks. I still have not rendered a graphic to my screen yet, and it's very depressing. It feels like I'm not getting anywhere, but I'm kinda just skipping around it, setting everything else up like input and whatnot, but I really wanna see a few results. After running my code in debug, it seems that everything is being set up correctly, and the texture is loading in fine.

Here lies all of my graphics rendering code thus far:

bool TitleScreen::Run()
{
while(Msg.message != WM_QUIT && isPlaying)
{
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
D3D_device->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_RGBA(0,0,192,255),1.0f,0);
D3D_device->BeginScene();

sprite->Draw(bg,srcRectBg,NULL,NULL,0x00000000);

D3D_device->EndScene();
D3D_device->Present(NULL,NULL,NULL,NULL);
}
}
return false;

}






Is there something small that I'm overlooking? Because sprite->Draw() is not drawing my background image. All I see is a blue back buffer.

bg.bmp is a 1024x1024 image with my 640x480 background lying in the top left corner. So I'm specifying a rectangle because that's the only part I want to use of that texture. I'm dislaying it at (0,0) all the time, so my destination vector is NULL.

Share this post


Link to post
Share on other sites

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