--- font.c	2011-09-24 00:22:07.479796663 -0500
+++ font.c.new6	2011-09-24 00:21:29.031033310 -0500
@@ -5,7 +5,7 @@
  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  *                     \/            \/     \/    \/            \/
- * $Id: font.c 29523 2011-03-05 18:36:51Z kugel $
+ * $Id$
  *
  * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
  *
@@ -101,6 +101,9 @@
     alloc->font.buffer_start += diff;
     alloc->font.buffer_end += diff;
     alloc->font.buffer_position += diff;
+
+    alloc->font.cache._index += diff;
+
     return BUFLIB_CB_OK;
 }
 static void lock_font_handle(int handle, bool lock)
@@ -559,10 +562,13 @@
 static void
 load_cache_entry(struct font_cache_entry* p, void* callback_data)
 {
-    struct font* pf = callback_data;
+    int handle = buflib_allocations[(int)callback_data];
+    struct buflib_alloc_data *pdata = core_get_data(handle);
+    struct font* pf = &pdata->font;
     unsigned short char_code = p->_char_code;
     unsigned char tmp[2];
 
+    lock_font_handle(handle, true);
     if (pf->file_width_offset)
     {
         int width_offset = pf->file_width_offset + char_code;
@@ -596,6 +602,8 @@
     lseek(pf->fd, file_offset, SEEK_SET);
     int src_bytes = glyph_bytes(pf, p->width);
     read(pf->fd, p->bitmap, src_bytes);
+
+    lock_font_handle(handle, false);
 }
 
 /*
@@ -625,9 +633,28 @@
         pf->width? pf->width[char_code]: pf->maxwidth;
 }
 
+static int pf_to_handle(struct font* pf)
+{
+    int i;
+    for (i=0; i<MAXFONTS; i++)
+    {
+        int handle = buflib_allocations[i];
+        if (handle > 0)
+        {
+            struct buflib_alloc_data *pdata = core_get_data(handle);
+            if (pf == &pdata->font)
+                return i;
+        }
+    }
+    return -1;
+}
+
 const unsigned char* font_get_bits(struct font* pf, unsigned short char_code)
 {
     const unsigned char* bits;
+    int handle = pf_to_handle(pf);
+    /* if (handle < 0)
+        return NULL; */
 
     /* check input range*/
     if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size)
@@ -637,7 +664,7 @@
     if (pf->fd >= 0 && pf != &sysfont)
     {
         bits =
-            (unsigned char*)font_cache_get(&pf->cache,char_code,load_cache_entry,pf)->bitmap;
+            (unsigned char*)font_cache_get(&pf->cache,char_code,load_cache_entry, &handle)->bitmap;
     }
     else
     {
