🔒 Locked
DirectDraw Surface Problem
Advertisement
Original Post
I have a very strange problem here, for some reason my program won''t create the primary surface using
if(FAILED(lpDD->CreateSurface(&ddsd_, &primary_, NULL)))
it gets to that line and stops. I''ve tried everything I can think of, taking it out of my class and putting it directly in WinMain, initializing the window several different ways, initializing directdraw several different ways, even intializing directdraw through the COM objects, all with the exact same result. I have all the includes I need and there are no problems until it reaches this point. If anyone has any idea what may be causing this, I could really use the help, thanks.
__________________________________________
We get signal.
There are bombs exploding all around us!!
Well, things seem to be working now. The code to initialize and do everything is exactly the same as before, but I put most of it into main (the initializing direct draw stuff), the surfaces seem to be created ok now (this is done in a seperate class) so I don''t really have any idea what the problem was. The only thing I can think of is that I could have passed the LPDIRECTDRAW7 thing wrong, don''t know how though. After I know things are working and stable, I may try to break things out again, but who knows.
__________________________________________
We get signal.
There are bombs exploding all around us!!
__________________________________________
We get signal.
There are bombs exploding all around us!!
2 Anonymous
I checked my code for DD7 init and it looks almost exactly
the same, except that it''s located in WinMain().
It works fine with DX Retail and it fails to CreateSurface with DX Debug (for whatever reason). So, make sure you run DX Retail.
Also, you gotta be sure that DDWnd constructor is launched from the main thread, or else...
I checked my code for DD7 init and it looks almost exactly
the same, except that it''s located in WinMain().
It works fine with DX Retail and it fails to CreateSurface with DX Debug (for whatever reason). So, make sure you run DX Retail.
Also, you gotta be sure that DDWnd constructor is launched from the main thread, or else...
1. In a debugger (F5 with debug app in MSVC), calling GetModuleHandle to find the application instance can end up getting the DEBUGGERS instance. Your program is run as a child process - I won''t go into the gory details, but normally its impossible for two applications to run at the same time and see each others address space - MSVC/a debugger has to do some nasty stuff to make it sort of appear like its happened.
2. If any objects based on DDWnd are global/static in your program, then thats ***VERY BAD***. Static/Global constructors get called **before** the C runtime library initialisation for your application has completed (if anyone needs the gory but clever details [__xc_a etc] I''ll explain them).
Doing any allocation or system coding in a constructor (static or not) is bad programming practice IMO - the only way to get errors back to client code is via exceptions, and a constructor isn''t a very nice place to cause one from (ie. object in half constructed state, partway through the allocator code).
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
2. If any objects based on DDWnd are global/static in your program, then thats ***VERY BAD***. Static/Global constructors get called **before** the C runtime library initialisation for your application has completed (if anyone needs the gory but clever details [__xc_a etc] I''ll explain them).
Doing any allocation or system coding in a constructor (static or not) is bad programming practice IMO - the only way to get errors back to client code is via exceptions, and a constructor isn''t a very nice place to cause one from (ie. object in half constructed state, partway through the allocator code).
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
2 Anonymous
>Now I just get a screen with the default window color
You didn't expect something to show up before you actually draw it, did you? Also, make sure you intercept WM_ERASEBKGND, WM_NCPAINT, WM_NCCALCSIZE and never allow them to DefWndProc. Otherwise, the system redraws your window each time you flip.
BTW, I personally keep my draw-flip loop in a separate thread,
apart from the MessageLoop.
Edited by - Friday13 on August 13, 2001 3:44:53 AM
>Now I just get a screen with the default window color
You didn't expect something to show up before you actually draw it, did you? Also, make sure you intercept WM_ERASEBKGND, WM_NCPAINT, WM_NCCALCSIZE and never allow them to DefWndProc. Otherwise, the system redraws your window each time you flip.
BTW, I personally keep my draw-flip loop in a separate thread,
apart from the MessageLoop.
Edited by - Friday13 on August 13, 2001 3:44:53 AM
Anonymous was me. Anyway, I intercepted the 3 messages, but I still get the grey screen with the hour glass. I placed a sound file to play each time it does the flip routine and the sound never plays which leads me to believe it never makes it to the flip routine.
Invader X
http://www.invadersrealm.com
Invader X
http://www.invadersrealm.com
Invader X
Nice to meet you.
Like I said, try to Clear2 at least (let alone drawing something)so you can see if any change happens to the back buffer at all. Besides, i''m not sure how this construction:
if PeekMessage(...) Translate ELSE flip
should work. Maybe you''re getting some constant flow of incoming messages so you never get to ELSE clause. Or, maybe you''re getting no messages and, since you don''t draw anything, it''s flipping so fast you don''t even notice, but you can''t say ''cos you didn''t make changes to the surfaces.
Nice to meet you.
Like I said, try to Clear2 at least (let alone drawing something)so you can see if any change happens to the back buffer at all. Besides, i''m not sure how this construction:
if PeekMessage(...) Translate ELSE flip
should work. Maybe you''re getting some constant flow of incoming messages so you never get to ELSE clause. Or, maybe you''re getting no messages and, since you don''t draw anything, it''s flipping so fast you don''t even notice, but you can''t say ''cos you didn''t make changes to the surfaces.
Thanks. It works now.
You were right that it was set up to have a constant flow of messages. When I double checked it again I noticed that I was using PM_NOREMOVE which left the messages in the queue so they were always being read again. I switched to PM_REMOVE and it works.
Thanks again =)
You were right that it was set up to have a constant flow of messages. When I double checked it again I noticed that I was using PM_NOREMOVE which left the messages in the queue so they were always being read again. I switched to PM_REMOVE and it works.
Thanks again =)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement