Jump to content
  • Advertisement

Archived

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

+AA_970+

Will it work???

This topic is 6547 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

Will this work: LPDIRECTDRAWSURFACE7 *surface; surface = new LPDIRECTDRAWSURFACE7[x]; It compiles, but will it crash the app? Also if it does work, how do i free the memory, delete [] surface; or surface[x]->Release(); (x is incremented in a loop for all the surfaces created) +AA_970+

Share this post


Link to post
Share on other sites
Advertisement
Correct me if I''m wrong, but don''t you have to get the display device to create surfaces????

Jans.

Share this post


Link to post
Share on other sites
I''m not creating surfaces in the code shown. I should explain, what i''m trying to load sprites onto surfaces at run time. So i want to know if this will work so i could access the surfaces like:

surface[0]->Blt(...)
Surface[1]->Blt(...)
...

+AA_970+

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m not creating surfaces in the code shown. I should explain, what i''m trying to load sprites onto surfaces at run time. So i want to know if this will work so i could access the surfaces like:

surface[0]->Blt(...)
Surface[1]->Blt(...)
...

+AA_970+

Share this post


Link to post
Share on other sites
Well I tried it out and it works

But i still have a question,

I can only do
"delete [] surface;"

i cannot do
"surface->Release();"
This causes a GPF error.

So is it ok to use delete?
Is it deallocating the memory?

BTW, sorry about the duplicate post, my browser was acting up.



+AA_970+

Share this post


Link to post
Share on other sites
Just thought i''d resurface the thread, i really need an answer to this.

Is not using Release on a surface bad, if you use delete instead?
If you don''t know what i''m talking about read the previous post.

Thanks for any help.

+AA_970+

Share this post


Link to post
Share on other sites
When you release the surface, call Release() on every surface eg

surface[0]->Release();
surface[1]->Release(); etc rather than just surface->Release();

I believe you should always call Release() on DD surfaces, and call it before you delete them.

===========================
No sense being pessimistic. It wouldn''t work anyway.

Share this post


Link to post
Share on other sites
There''s no reason that surface[x]->Blt(...) should work and surface[x]->Release() shouldn''t. If surface[x] is a valid surface pointer, then calls to any method (including Release) should work. Here''s what I think it should look like:
    
// Create an array of pointers

LPDIRECTDRAWSURFACE7 *surface = new LPDIRECTDRAWSURFACE7[x];
if (NULL == surface) { <oom error> }

// Null out all of the pointers

memset(surface, 0, x * sizeof(surface[0]));

// Fill pointers somehow

...

// Use surfaces

...

// Release all of the surfaces

for (i = 0; i < x; i++)
{
if (NULL != surface<i>)
{
surface[i]->Release();

// This is only necessary if you may

// reuse the surface array.

surface[i] = NULL;
}
}

// Delete the array of pointers

delete[] surface;
surface = NULL;

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!