Ordered releasing of surfaces? [Archive] - C Board

PDA

View Full Version : Ordered releasing of surfaces?


Hunter2
12-26-2002, 10:13 PM
Ok, the book I was reading had some code and said something about releasing surfaces in reverse order that they were gotten in, but I was sort of confused and I really don't know exactly how evil it would be to jumble up the order that I release them in. For example:


IDirectDrawSurface7* a = get_a_surface();
IDirectDrawSurface7* b = get_a_surface();
IDirectDrawSurface7* c = get_a_surface();

//**********************

c->Release(); //How the
b->Release(); //book
a->Release(); //did it

//**********************

b->Release(); //Would
c->Release(); //this
a->Release(); //be bad?

Eibro
12-26-2002, 10:33 PM
Objects are automagically destructed in reverse order of construction, this is probably the reason for releasing the surfaces in reverse order. I guess it's "evilness" depends on how you aquire the surface in the first place, and whether or not they depend on eachother.

Hunter2
12-26-2002, 10:41 PM
Objects are automagically destructed in reverse order of constructionThen why do I need to destruct them myself?

I guess it's "evilness" depends on how you aquire the surface in the first place, and whether or not they depend on eachother.Oh, that makes sense :). So if I have a primary surface and get an attached surface, the attached one has to be released first - but if the only link between 2 surfaces is that they're created with the same DirectDraw object, they can be released in any order?

nvoigt
12-27-2002, 09:18 AM
If the surfaces aren't connected ( ie primary and attached ) you can release them in any order.

Eibro
12-27-2002, 09:30 AM
Originally posted by Hunter2
Then why do I need to destruct them myself?
Because they're pointers. I'm talking about regular variables created on the stack. For example:



class obj
{
public:
obj() { cout << "obj::obj()\n"; }
~obj() { cout << "obj::~obj()\n"; }
};

int main {
obj a;
obj b;
obj c;

cin.get();
return 0;
}

Hunter2
12-27-2002, 12:02 PM
If the surfaces aren't connected ( ie primary and attached ) you can release them in any order.Ok, thanks :)

Because they're pointers. I'm talking about regular variables created on the stack.So in your example, a b and c will be destructed in c-b-a order?

Hunter2
12-27-2002, 04:28 PM
Hey, new problem everyone :D

In my book:

-Declare a DDSURFACEDESC2
-fill it in (with one of the flags being DDSCAPS_COMPLEX)
-Create a primary surface with it
-get an attached surface (a backbuffer)
-do stuff with those
-release the attached surface
-release the primary surface


On my version of MSDN:

DDSCAPS_COMPLEX
Indicates a complex surface is being described. A complex surface results in the creation of more than one surface. The additional surfaces are attached to the root surface. The complex surface can be destroyed only by destroying the root.
Do I really need to manually release the attached surface (i.e. if I kill the root will the branches die on their own?), or does the bolded part only mean that the surface won't be completely destroyed unless I release the primary surface also?

Leeman_s
12-27-2002, 10:13 PM
btw, what book are you reading?

Hunter2
12-27-2002, 11:16 PM
Windows Game Programming for Dummies by André LaMothe. For all those out there who want to learn DirectX, I have 4 words for you: DON'T GET THIS BOOK! :D Between typos, redundant code and semi-poor explanations (don't listen to what the book reviews tell you!), I've had a hard time piecing together what does what; and it doesn't do things the easy way (i.e. load bitmaps by hand instead of using GDI, etc.).

So does anybody have any advice for me other than to get another book? :(