1
0
forked from 0ad/0ad

fix 2 lib resource leaks; update h_mgr dox

This was SVN commit r179.
This commit is contained in:
janwas 2004-03-07 15:00:51 +00:00
parent dc4cc78e7b
commit ce9c517eb4
3 changed files with 29 additions and 11 deletions

View File

@ -175,15 +175,11 @@ extern int h_free(Handle& h, H_Type type);
extern Handle h_find(H_Type type, uintptr_t key);
*/
// return a pointer to handle data
// return a pointer to handle data, or 0 on error
extern void* h_user_data(Handle h, H_Type type);
extern const char* h_filename(Handle h);
// some resource types are heavyweight and reused between files (e.g. VRead).
// this reassigns dst's (of type <type>) associated file to that of src.
int h_reassign(const Handle dst, const H_Type dst_type, const Handle src);
extern int res_cur_scope;
@ -251,8 +247,8 @@ guide to defining and using resources
2) declare its control block:
struct Res1
{
void* data1; data loaded from file
int flags; set when resource is created
void* data1; // data loaded from file
int flags; // set when resource is created
};
3) build its vtbl:
@ -335,13 +331,28 @@ guide to defining and using resources
int res1_free(Handle& h)
{
return h_free(h, H_Res1);
// zeroes h afterwards
}
the h parameter is zeroed by h_free.
(this layer allows a res_load interface on top of all the loaders,
and is necessary because your module is the only one that knows H_Res1).
6) done. the resource will be freed at exit (if not done already).
here's how to access the control block, given a handle:
Handle h;
a) H_DEREF(h, Res1, r);
creates a variable r of type Res1*, which points to the control block
of the resource referenced by h. returns "invalid handle"
(a negative error code) on failure.
b) Res1* r = h_user_data(h, H_Res1);
if(!r)
; // bail
useful if H_DEREF's error return (of type signed integer) isn't
acceptable. otherwise, prefer a) - this is pretty clunky, and
we could switch H_DEREF to throwing an exception on error.
*/

View File

@ -50,9 +50,9 @@ void get_cur_resolution(int& xres, int& yres)
int win_get_gfx_card()
{
// EnumDisplayDevices is not available on Win95 or NT
HMODULE h = LoadLibrary("user32.dll");
HMODULE hUser32Dll = LoadLibrary("user32.dll");
int (WINAPI *pEnumDisplayDevicesA)(void*, DWORD, void*, DWORD);
*(void**)&pEnumDisplayDevicesA = GetProcAddress(h, "EnumDisplayDevicesA");
*(void**)&pEnumDisplayDevicesA = GetProcAddress(hUser32Dll, "EnumDisplayDevicesA");
if(pEnumDisplayDevicesA)
{
DISPLAY_DEVICEA dev;
@ -63,6 +63,7 @@ int win_get_gfx_card()
return 0;
}
}
FreeLibrary(hUser32Dll);
return -1;
}

View File

@ -333,6 +333,12 @@ inline void SDL_GL_SwapBuffers()
void SDL_Quit()
{
if(hDC != INVALID_HANDLE_VALUE)
{
ReleaseDC(hWnd, hDC);
hDC = (HDC)INVALID_HANDLE_VALUE;
}
if(hWnd != INVALID_HANDLE_VALUE)
{
DestroyWindow(hWnd);