Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!bloom-beacon!lightning.mcrcim.mcgill.EDU!mouse From: mouse@lightning.mcrcim.mcgill.EDU Newsgroups: comp.windows.x Subject: Re: problem with colormap Message-ID: <9011091424.AA06728@lightning.McRCIM.McGill.EDU> Date: 9 Nov 90 14:24:15 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 56 > I was trying to get a ray tracing program that someone else wrote to > work on my DECStation 5000/200. The program fails when it attempts > to display an image and I traced the problem down to a section of > code that creates a new colormap. Below is the code fragment that I > think is causing problems. [edited for compactness -dM] > i = XMatchVisualInfo(display, theScreen, depth, PseudoColor, &visualinfo); > if (!i) i = XMatchVisualInfo(display, theScreen, depth, TrueColor, &visualinfo); > if (!i) exit(1); > visual = visualinfo.visual; > rootw = RootWindow(display, theScreen); > theGC = DefaultGC(display, theScreen); > cmap = XCreateColormap(display, rootw, visual, AllocAll); > ... > XStoreColors(display, cmap, carray, CMAPSIZE); > The first call to XMatchVisualInfo always fails but the second call > succeeds so apparently the visual class is TrueColor. (Or rather, no PseudoColor visual is available but a TrueColor visual is. On color displays there often (usually?) is no "the" visual class.) > This causes the XCreateColormap call to fail with a BadMatch error. > I tried fixing this problem by passing AllocNone instead of AllocAll > but this caused a protection error when XStoreColors was called. The problem is that you simply can't treat PseudoColor and TrueColor the same. For PseudoColor you need to XCreateColormap(...,AllocAll); XStoreColors(...); whereas for TrueColor you simply XCreateColormap(...,AllocNone); Note though that if the *default* visual is a TrueColor then there is no need to create a new colormap; you can simply use the default. > Can anybody offer any insight into this problem and suggest a > workaround ? I would guess that the code was developed on a system with PseudoColor available, so the TrueColor code was untested. For a workaround, I would recommend remembering somewhere whether the visual is PseudoColor or TrueColor and doing the colormap differently, as I sketched above. Note that you need to take care that your pixel values are correct for the desired colors in the TrueColor case; you can't assign them yourself as you can for PseudoColor. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu