Ordered releasing of surfaces?

This is a discussion on Ordered releasing of surfaces? within the Game Programming forums, part of the General Programming Boards category; Ok, the book I was reading had some code and said something about releasing surfaces in reverse order that they ...

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Ordered releasing of surfaces?

    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:

    Code:
    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?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    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.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Objects are automagically destructed in reverse order of construction
    Then 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?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    If the surfaces aren't connected ( ie primary and attached ) you can release them in any order.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    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:

    Code:
    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;
    }

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    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?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hey, new problem everyone

    In my book:
    Code:
    -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?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    btw, what book are you reading?

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    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! 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?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do maps keep elements ordered?
    By nucleon in forum C++ Programming
    Replies: 7
    Last Post: 11-08-2008, 02:39 PM
  2. Bouncing off surfaces
    By valaris in forum Game Programming
    Replies: 4
    Last Post: 09-02-2008, 07:10 PM
  3. how to ordered const structs
    By tnr in forum C Programming
    Replies: 2
    Last Post: 12-14-2007, 06:13 AM
  4. DX surfaces or textures?
    By maxthecat in forum Game Programming
    Replies: 7
    Last Post: 01-26-2006, 10:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21