Will it work???

Started by
10 comments, last by +AA_970+ 23 years, 9 months ago
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+
Advertisement
Correct me if I''m wrong, but don''t you have to get the display device to create surfaces????

Jans.
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+
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+
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+
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+
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.
===========================There are 10 types of people in the world. Those that understand binary and those that don't.( My views in no way reflect the views of my employer. )
I tried that but i get a general protection fault error .

+AA_970+
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 pointersLPDIRECTDRAWSURFACE7 *surface = new LPDIRECTDRAWSURFACE7[x];if (NULL == surface) { <oom error> }// Null out all of the pointersmemset(surface, 0, x * sizeof(surface[0]));// Fill pointers somehow...// Use surfaces...// Release all of the surfacesfor (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 pointersdelete[] surface;surface = NULL;    
but

surface->Release();

will delete itself through COM (right?)....
if that is the case, since you did not create it
through COM, it shouldn''t work...



ill-lusion.com

ziggy@ill-lusion.com
laxdigital.com
[email=ziggy@laxdigital.com]ziggy@laxdigital.com[/email]

This topic is closed to new replies.

Advertisement