[comp.windows.x] Problems freeing an XFontStruct

toml@marvin.Solbourne.COM (Tom LaStrange) (04/12/91)

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);

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.

So is it possible to free a font structure obtained using a GC rather
than a font ID?

--
(I kid you not)Tom LaStrange        toml@Solbourne.COM

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (04/13/91)

> 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