diff --git a/source/lib/res/font.cpp b/source/lib/res/font.cpp index 5bb71c0e17..631662d30f 100755 --- a/source/lib/res/font.cpp +++ b/source/lib/res/font.cpp @@ -173,7 +173,7 @@ static int Font_reload(Font* f, const char* fn) // load glyph texture const Handle ht = tex_load(tex_filename); if(ht <= 0) - return ht; + return (int)ht; tex_upload(ht); const int tex_dim = 256; diff --git a/source/lib/res/h_mgr.cpp b/source/lib/res/h_mgr.cpp index 3f8ccfe132..7f54b3c3d5 100755 --- a/source/lib/res/h_mgr.cpp +++ b/source/lib/res/h_mgr.cpp @@ -134,7 +134,9 @@ static i32 last_in_use = -1; // don't search unused entries // get an array entry (array is non-contiguous). // fails (returns 0) if idx is out of bounds, or if accessing a new page // for the first time, and there's not enough memory to allocate it. -// used by h_alloc to find a free entry. +// used by h_data, and alloc_idx to find a free entry. +// beware of conflict with h_data_any_type: +// our i32 param silently converts to its Handle (= i64) param. static HDATA* h_data(const i32 idx) { // don't compare against last_in_use - this is called before allocating @@ -156,15 +158,18 @@ static HDATA* h_data(const i32 idx) -int hdataseq=0; +int h_data_tag = 0; // get HDATA for the given handle. verifies the handle // isn't invalid or an error code, and checks the tag field. -// used by functions callable for any handle type, e.g. h_filename. -static HDATA* h_data(const Handle h) +// used by the few functions callable for any handle type, e.g. h_filename. +static HDATA* h_data_any_type(const Handle h) { -hdataseq++; -_heapchk(); + h_data_tag++; + +#ifdef PARANOIA + check_heap(); +#endif // invalid, or an error code if(h <= 0) @@ -193,7 +198,7 @@ _heapchk(); // used by most functions accessing handle data. static HDATA* h_data(const Handle h, const H_Type type) { - HDATA* hd = h_data(h); + HDATA* hd = h_data_any_type(h); if(!hd) return 0; @@ -440,27 +445,15 @@ void* h_user_data(const Handle h, const H_Type type) return hd? hd->user : 0; } + const char* h_filename(const Handle h) { - HDATA* hd = h_data(h); + HDATA* hd = h_data_any_type(h); + // don't require type check: should be useable for any handle, + // even if the caller doesn't know its type. return hd? hd->fn : 0; } -/* -// some resource types are heavyweight and reused between files (e.g. VRead). -// this reassigns dst's (of type ) associated file to that of src. -int h_reassign(const Handle dst, const H_Type dst_type, const Handle src) -{ - HDATA* hd_dst = h_data(dst, dst_type); - HDATA* hd_src = h_data(src); - if(!hd_dst || !hd_src) - return -1; - - hd_dst->fn = hd_src->fn; - hd_dst->key = hd_src->key; - return 0; -} -*/ int h_reload(const char* fn) { diff --git a/source/lib/sysdep/sysdep.cpp b/source/lib/sysdep/sysdep.cpp index ca2fedbf19..5052f6c4f3 100755 --- a/source/lib/sysdep/sysdep.cpp +++ b/source/lib/sysdep/sysdep.cpp @@ -23,4 +23,9 @@ void debug_out(const char* fmt, ...) va_end(args); } + +void check_heap() +{ +} + #endif // #ifndef _WIN32 \ No newline at end of file diff --git a/source/lib/sysdep/sysdep.h b/source/lib/sysdep/sysdep.h index 123b87ea13..bb37b1f2c8 100755 --- a/source/lib/sysdep/sysdep.h +++ b/source/lib/sysdep/sysdep.h @@ -10,6 +10,8 @@ extern "C" { extern void display_msg(const wchar_t* caption, const wchar_t* msg); extern void debug_out(const char* fmt, ...); +extern void check_heap(); + #ifdef __cplusplus } #endif diff --git a/source/lib/sysdep/win/win.cpp b/source/lib/sysdep/win/win.cpp index 37cc45e9e7..f4bf3b5d64 100755 --- a/source/lib/sysdep/win/win.cpp +++ b/source/lib/sysdep/win/win.cpp @@ -30,6 +30,13 @@ // (they're more convenient) // + +void check_heap() +{ + _heapchk(); +} + + void display_msg(const wchar_t* caption, const wchar_t* msg) { MessageBoxW(0, msg, caption, MB_ICONEXCLAMATION);