• Advertisement

Archived

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

Will it work???

This topic is 6420 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
I tried that but i get a general protection fault error .

+AA_970+

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
Syzygy - i did exactly what you said, and i get the GPF error.

Ziggy5000 - I don''t understand what your saying (probably because i don''t know anything about COM).

Let''s say i have something like LPDIRECTDRAWSURFACE7 surface[12] (in which case Release would work), this mean that 12 pointers are created through COM?

But if i have LPDIRECTDRAWSURFACE7 *surface and use new, the surface pointers are not created through COM?

If the way i created the pointers are not through COM, then i don''t need to call Release, right?

+AA_970+

Share this post


Link to post
Share on other sites
Ahhh, i''m so mad at myself. The problem wasn''t with the surfaces after all. I''m just learning C++ and didn''t know that the destructor is called when the program terminates, and i didn''t check if the surfaces were NULL before releasing them. So the GPF error was b/c i was attempting to release the surfaces twice.

btw, i do realize the explanation to the COM and surface pointer thing i gave in my previous post is complete crap

Anyways, thanx alot guys

+AA_970+

Share this post


Link to post
Share on other sites

  • Advertisement