• Advertisement

Archived

This topic is now archived and is closed to further replies.

Error Creating off screen surface

This topic is 6553 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've been creating a DirectDraw Engine, and its worked fine on my computer, but then I tried running it on some other computers, and it wont work. Ive tracked the error down to my CreatSurface function, and well.. here take a look: // initializes a direct draw struct, basically zeros it and sets the dwSize field #define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); } LPDIRECTDRAWSURFACE4 CDDraw_Manager::CreateSurface(int width, int height, int mem_flags, int ColorKey) { ////////////////////////////////////////////////////////////////////////////////////// // Purpose: This Creates am offscreen surface for CImages // // //////////////////////////// // // // ////////////////////////////////////////////////////////////////////////////////////// LPDIRECTDRAWSURFACE4 lpdds; //This is just temporary - it gets return and never used again by CDDraw_Manager //ddsd is a member of CDDraw_Manager. It is a DDSURFACEDESC2 DDRAW_INIT_STRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_WIDTH / DDSD_HEIGHT; //lets it know all these are valid values ddsd.dwWidth = width; ddsd.dwHeight = height; //Tell it, its offscreen and to the right memory ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN / mem_flags; //this is what tells it to be created in system or VRAM. use VRAM when possible! //create the surface - THIS IS WHAT ERRORS if(FAILED(lpdd4->CreateSurface(&ddsd, &lpdds, NULL))) { ErrorMessage("Error creating offscreen surface!"); return(NULL); } //transparency if(ColorKey >= 0) //this just makes sure they arent trying to make color -12323 transparent { DDCOLORKEY color_key; color_key.dwColorSpaceHighValue = ColorKey; color_key.dwColorSpaceLowValue = ColorKey; //set key for blitting lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key); } //this is what we came for in the first place: the surface return(lpdds); } The ErrorMessage function opens an error file, and writes to it. And on the 2 other computers I've tried running my program on, thats what has happened. Any ideas? You can download the program at www.123.net/~sourmosh/skeltest.zip if you want. I can send anyone the full source if they need it. Thanks, Dave Edited by - ratman on 3/12/00 12:31:38 PM

Share this post


Link to post
Share on other sites
Advertisement
hi mate,
what about scope ? you say that you have a member in this class called ddsd ?

why do you have that in there ? when really it''s nothing to create a local scope''d ddsd in the function, then you eliminate all other problems you might have with this. Reason I say this is cause we tried to create a class based renderer, a class that would take in and hold all details for DirectX, then if you needed a sprite, or whatever pasted around, you ask the class etc etc, seems like you are doing the same, we had problems with scope. Try to make everything local to where you are needing them, global params are not really a good idea in classes, especially when you dont need to.

send me the source to chris_thomas@hotmail.com

if you want me to look at it, I dont mind, will give me some experience at reading other peoples code.

oh yeah, I thought you said that it writes errors to an output file ? well, I downloaded your zip and well, it ran, crashed out (I assume cause it did nothing) and didnt write to any file, so whats the score here ?

Share this post


Link to post
Share on other sites
If you''re writing errors to a file, make sure that the file is flushed after each message is written so that the file will be complete if/when it crashes. If you were using an ofstream here, use endl to terminate the line, for instance. Obviously, if it crashes with an unknown error that you can''t trap, the above is irrelevant.

Check the return value from CreateSurface. Someone recently posted a function which takes a DirectDraw error code and returns a more informative message telling what it was. Alternatively, look through the docs and paste in some lines after the error is caught like:

if (result == DDERR_INVALIDPARAMS)
Output "DDERR_INVALIDPARAMS";

You will have to store the result of the CreateSurface function for this. I use a syntax like:

HRESULT result;
if(FAILED(result = lpdd4->CreateSurface(&ddsd, &lpdds, NULL)))


Good luck.

Share this post


Link to post
Share on other sites
Um, Spiff, the board reformats the OR operator to ''/''. The code to set the flags looks find.

Share this post


Link to post
Share on other sites
Oh, sorry, I''ll delete that post, I didn''t know about that.

============================
Daniel Netz, Sentinel Design
"I'm not stupid, I'm from Sweden" - Unknown

Share this post


Link to post
Share on other sites

  • Advertisement