Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!emory!att!ucbvax!bloom-beacon!dont-send-mail-to-path-lines From: mouse@lightning.mcrcim.mcgill.EDU (der Mouse) Newsgroups: comp.windows.x Subject: Re: Problems freeing an XFontStruct Message-ID: <9104130157.AA08644@lightning.McRCIM.McGill.EDU> Date: 13 Apr 91 01:57:37 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 45 > I'm having problems freeing an XFontStruct, here's the code: > GC gc; > XFontStruct *fsp; > gc = XCreateGC(dpy, win, 0, 0); > fsp = XQueryFont(dpy, XGContextFromGC(gc)); > XFreeFont(dpy, fsp); Without prototypes in scope, that first call is wrong (it's passing two ints instead of an unsigned long and an XGCValues pointer). But that is probably not related. > This generates the following protocol error: > X Error of failed request: BadFont (invalid Font parameter) > Major opcode of failed request: 46 (X_CloseFont) > Resource id in failed request: 0x1500002 > Serial number of failed request: 6 > Current serial number in output stream: 11 > I presume because the font ID in the XFontStruct is actually the > graphics context ID and XFreeFont() assumes it's a font ID. Most likely. > So is it possible to free a font structure obtained using a GC rather > than a font ID? XFreeFont() is probably not what you want. XFreeFont() not only frees the XFontStruct, it also unloads the font. You probably don't want to do that; XQueryFont() does not load a font, it merely queries an already-loaded font. To just free the XFontStruct, the Xlib document says you should use XFreeFontInfo(). There appears to be no way to unload a font for which you no longer have an XFontStruct; while aesthetically unpleasant, this does not really strike me as a problem. (If you really must, you can use XQueryFont to get something to call XFreeFont with, though it seems rather inefficient.) der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu