From 851a30215fcbfaf82ec8ee6f73e864b48f34fbfb Mon Sep 17 00:00:00 2001 From: janwas Date: Thu, 16 Dec 2004 01:17:50 +0000 Subject: [PATCH] add h_add_ref; add leak report (currently disabled, since all textures are leaked) This was SVN commit r1511. --- source/lib/res/h_mgr.cpp | 23 +++++++++++++++++++++++ source/lib/res/h_mgr.h | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/source/lib/res/h_mgr.cpp b/source/lib/res/h_mgr.cpp index de3fd024e4..fd0c31d979 100755 --- a/source/lib/res/h_mgr.cpp +++ b/source/lib/res/h_mgr.cpp @@ -444,6 +444,9 @@ void h_mgr_shutdown() if(!hd->tag) continue; +// if(hd->refs != 0) +// debug_out("leaked %s from %s\n", hd->type->name, hd->fn); + // disable caching; we need to release the resource now. hd->keep_open = 0; hd->refs = 0; @@ -740,6 +743,26 @@ int h_force_free(Handle h, H_Type type) } +// increment Handle 's refcount. +// only meant to be used for objects that free a Handle in their dtor, +// so that they are copy-equivalent and can be stored in a STL container. +// do not use this to implement refcounting on top of the Handle scheme, +// e.g. loading a Handle once and then passing it around. instead, have each +// user load the resource; refcounting is done under the hood. +void h_add_ref(Handle h) +{ + HDATA* hd = h_data_tag(h); + if(!hd) + { + debug_warn("h_add_ref: invalid handle"); + return; + } + + if(!hd->refs) + debug_warn("h_add_ref: no refs open - resource is cached"); + hd->refs++; +} + int res_cur_scope; diff --git a/source/lib/res/h_mgr.h b/source/lib/res/h_mgr.h index 0073e5f481..4f6e610c7b 100755 --- a/source/lib/res/h_mgr.h +++ b/source/lib/res/h_mgr.h @@ -209,6 +209,14 @@ extern int res_cur_scope; // at that point, all (cached) OpenAL resources must be freed. extern int h_force_free(Handle h, H_Type type); +// increment Handle 's refcount. +// only meant to be used for objects that free a Handle in their dtor, +// so that they are copy-equivalent and can be stored in a STL container. +// do not use this to implement refcounting on top of the Handle scheme, +// e.g. loading a Handle once and then passing it around. instead, have each +// user load the resource; refcounting is done under the hood. +extern void h_add_ref(Handle h); + extern void h_mgr_shutdown();