• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

jtecin

DD_Shutdown

15 posts in this topic

Try

int GFX_Shutdown(void)
{
if (lpddsback)
lpddsback->Release(); lpddsback=0;
if (lpddsprimary)
lpddsprimary->Release();lpddsprimary=0;
if (lpdd)
lpdd->Release();lpdd=0;
return 0;
}

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

0

Share this post


Link to post
Share on other sites
I can't see that doing this would be any different but from memory I always use:

if (lpddsback!=null){
  lpddsback->Release();
  lpddsback=null;
}

Most likly overkill on my part but I have never had any problems with it.

0

Share this post


Link to post
Share on other sites
i'm guessing your situation is using complex
which means when you kill the primary surface the release function for the attached back buffer gets called and so what may be going on is that you are first killing the back buffer but then you kill the primary buffer and it tries to release the back buffer again which is killed aand uh oh bad bad bad
your order of killing stuff is fine you jsut needed to point everything to NULL after killing it like the above posts say
0

Share this post


Link to post
Share on other sites
Look in the DX docs (I'm assuming you're using DX 7.0) under "When Reference Counts Will Change" and "Reference Counts for Complex Surfaces", and "Releasing Surfaces". In short, I think if you just create the flipping chain using create surface, you can release the whole thing by just releasing the primary surface. However if you get access to the back buffer by using GetAttachedSurface (which you probably do, I dont know how else you can do it!), you have to release the back buffer explicitly because GetAttachedSurface increases its ref count.
I think setting them to NULL after the release is a good idea, but it would only find bugs from your own code trying to reuse the object.
One thing you might consider doing is watching the ref count of both surfaces as your program progresses and terminates - just write something like:
int refcount;
Surf->AddRef();
refcount = (int) Surf->Release();
This should give you the current reference count without actually changing it, and you can see what is actually going on.
Finally, IDirectDraw and IDirectDraw2 interfaces, when released, also release all their children, wheras later interfaces don't, but this shouldn't be a problem for you because you are releasing the DD object last (the problem was with releasing children after the parent)
Hope this helps a little
-ns

[This message has been edited by NightShade (edited December 23, 1999).]

0

Share this post


Link to post
Share on other sites
Don't release the backbuffer if it's an attached surface. Just release the primary and it should release all surfaces attached to it.

You can test it out by releasing the primary surface, then try accessing the backbuffer - it should fail since it too was released.


Jim Adams

0

Share this post


Link to post
Share on other sites
Okay, I've tried everything but still no luck. FYI I am using DX 5.0 with VC++ 4.0(I know it is kind of out of date but can't afford anything else right now). Anyway, I thought I'd post the code for my GFX_init function:

int GFX_Init()
{
//Create DirectDraw object
if(DirectDrawCreate(NULL, &lpdd, NULL) != DD_OK)
{
MessageBox(main_window_handle,"Could Not Create Direct Draw","Error!",MB_OK);
return 0;
}
//Get exclusive mode but still allow ctrl & alt & delete
if(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT) != DD_OK)
{
MessageBox(main_window_handle,"Could Not Set ddraw cooperative","Error!",MB_OK);
return 0;
}
//Set the video mode to 640x460x16
if(lpdd->SetDisplayMode(640, 480, 16) != DD_OK)
{
MessageBox(main_window_handle,"Could Not set display mode","Error!",MB_OK);
return 0;
}
//Create the primary surface with a back buffer, make it "flipable"
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
if(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL) != DD_OK) return 0;

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if(lpddsprimary->GetAttachedSurface(&ddscaps, &lpddsback) != DD_OK) return 0;

return 1; //Return success!
}

0

Share this post


Link to post
Share on other sites
Clear the ddsd structure in there:

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
...


If that doesn't help, what exactly is happening when you exit? That compiler/dx version is fine - that's what I use on one of my systems.

Jim Adams

0

Share this post


Link to post
Share on other sites
When I try to exit, I get the usual windows "error beep", and black covers most of the screen except for a little on the right and bottom. The only way to get out is by using CTRL+ALT+DELETE and clicking on VC++ and END TASK. Ne1 know what's going on?
0

Share this post


Link to post
Share on other sites
Now I am wondering how your Window Procedure looks like

You should first release all your ddraw stuff, then call PostQuitMessage(0) or whatever......and then break.

Done that?

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

0

Share this post


Link to post
Share on other sites
Pretty sure I have that, here is my code:

if (KEY_DOWN(VK_ESCAPE))
{
Game_Shutdown(); //Close music, shutdown sound and shutdown graphics
PostQuitMessage(0);
}

It seems to work fine in my other programs.
0

Share this post


Link to post
Share on other sites
Not sure, but it seems you're trying to use the DDobjects/surfaces after they've been released. If the code from above is placed on the message handler, and you weren't setting the lpdds's and lpdd to zero or not checking in the main blitting/flipping action if they are different from zero, that would mess thing up, since it's possible the drawing will still happen after you release the objects... just a thought.
0

Share this post


Link to post
Share on other sites
Hmmmm.....I'm just wndering. I don't know that much about the window procedure but I do know that you have to break after each Window message.

Try putting a break after your PostQuitMessage(0). I think it's because of that why it is doing that stuff.

My reasoning:
If you don't break, it will return DefWindowProc on the end of your Window procedure, in that case it will try to access the DirectDraw stuff again, which will crash, because they don't exist anymore. I'm not quite sure if the postQuitMessage breaks out of it, so........give this a try.

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

0

Share this post


Link to post
Share on other sites
Actually, you'd return 0 - not break. A typical windows message function will break and fall down to the default message handler if you don't return.

I would suggest you make a very simple program that uses your init function, then immediately calls the shutdown function and exits. Don't even start the message loop. See what happens.

If it bombs, it most likely your init functions are not happening. If it works, then somewhere in the other program it's happening.

Also, when you structure your code, I would recomend you place the init function BEFORE the message loop, and the shutdown function AFTER the message loop - don't put either in the message loop under WM_DESTROY or WM_ACTIVE or whatever.


Jim

0

Share this post


Link to post
Share on other sites
Okay, I can't understand why this is not working. In my Game_Shutdown function, I call the following function to shut down direct draw:


int GFX_Shutdown(void)
{
if (lpddsback)
lpddsback->Release();
if (lpddsprimary)
lpddsprimary->Release();
if (lpdd)
lpdd->Release();

return 0;
}

Now, I can run my game and stuff and it works fine. But when I quit, this screws everything up. If I don't call this function, the program exits fine. However, I'm supposed to release the surfaces' resources, right? Anyway, I'm pretty sure there is nothing wrong with the actual function, so is there some way I could have screwed this up in a previous function, like initializes it wrong or something? Thanks for any help.

0

Share this post


Link to post
Share on other sites
I want to say thanks to all of you who replied as the problem finally got solved. I used PostQuitMessage(0) when escape is pushed and then in WM_QUIT I did Game_Shutdown and then used break. Once again, thanks.

0

Share this post


Link to post
Share on other sites