PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

FreeSurface() function and CGapiRGBASurface.

Is there a possibility to get the addition of a FreeSurface() function to the CGapiRGBASurface class?

While I haven't done any programming with GapiDraw yet, I am browsing through the documentation to see what it offers. I'm curious as to why CGapiRGBASurface isn't 1) Derived from CGapiSurface, and 2) Doesn't offer some of the flexibility that CGapiSurface does (ie; FreeSurface() function).

Please correct me if I'm wrong, but as a quick and dirty "resource manager," I was thinking something along of the lines of this: when a map is loaded, the appropriate graphics will be created, calling CGapiRGBASurface.CreateSurface(). When the map unloads and a new map is loading, graphics that are no longer needed will have FreeSurface() called, and graphics that will be needed will have CreateSurface() called. While the manager would obviously be more complex than this, it should give a basic idea of what I had in mind.

Is there no valid solution to this aside from going with CGapiSurface and forgetting about alpha channels? I did notice that there was a protected member which frees up resources used by CGapiRGBASurface, so I suppose I could just inherit from it and provide the functionality myself.
Well, the API exposes a method CGapiRGBASurface_Destroy for the CGapiDraw object, so there must be a method for it somewhere in the C++ side of things.
1. Freeing the surface for a CGapiRGBASurface

From the online documentation for GapiRGBASurface:
"All data allocated by a surface object will automatically be freed when the surface object is deleted. If you manually want to free all data allocated by a surface you can call CGapiRGBASurface::CreateSurface(0, 0, 0).""

We might add FreeSurface (which internally just calls CreateSurface(0,0,0)) to CGapiRGBASurface in an upcoming version.
Johan wrote:1. Freeing the surface for a CGapiRGBASurface

From the online documentation for GapiRGBASurface:
"All data allocated by a surface object will automatically be freed when the surface object is deleted. If you manually want to free all data allocated by a surface you can call CGapiRGBASurface::CreateSurface(0, 0, 0).""

We might add FreeSurface (which internally just calls CreateSurface(0,0,0)) to CGapiRGBASurface in an upcoming version.


Hmm.. I must have missed that, thanks for the reply.
Johan wrote:1. Freeing the surface for a CGapiRGBASurface

From the online documentation for GapiRGBASurface:
"All data allocated by a surface object will automatically be freed when the surface object is deleted. If you manually want to free all data allocated by a surface you can call CGapiRGBASurface::CreateSurface(0, 0, 0).""

We might add FreeSurface (which internally just calls CreateSurface(0,0,0)) to CGapiRGBASurface in an upcoming version.


When trying to call that function I get this error:

error C2668: 'CreateSurface' : ambiguous call to overloaded function
Yeap Johan,

CreateSurface(0,0,0) fails on GD 3.5 see the post above. So there must be something wrong with the implementation.

If you can fix and update the workaround it will be great.

Thanks.
I'd personaly rather see a FreeSurface function than a workaround.
For now I'd like to confirm whether or not this protected function works in a similar way as the "FreeSurface" function does:

FreeResources();

It's a protected member inside the CGapiRGBASurface class. I'm going to inherit from the class so I can get access to the function and use it as a replacement for FreeSurface. Would this be a recommended workaround until things get fixed in the next version? Or am I going to have to fall back to a previous version of GapiDraw?
denthorq wrote:Yeap Johan,

CreateSurface(0,0,0) fails on GD 3.5 see the post above. So there must be something wrong with the implementation.

If you can fix and update the workaround it will be great.

Thanks.


I tested the previous verion that they have on their site, and the error is in the older version as well.
Sorry for this issue. The documentation should state:

CreateSurface((DWORD)0, (DWORD)0, (DWORD)0);

This will free all resources allocated by the surface.

The reason CreateSurface(0,0,0) doesn't work is simply that we added support for the GapiVFS system in the last minute, and the compiler doesn't know what function to call if you simply use (0,0,0). I have updated the online documentation and I'll add the FreeSurface() function to 3.5b.
Great Johan !

Now I dont need to worry about freeing alpha images :D

Thanks.
Awsome.. thank you :)