Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GC create/copy problem

8 views
Skip to first unread message

NickC

unread,
Dec 3, 2009, 9:53:16 PM12/3/09
to
I'm having problems with creating and copying GCs.

First up, do I need to create an (initialised) GC before copying into it?
Or does XCopyGC actually initialise the structure with defaults for me?

Then, I'm getting segfaults on the Copy.

/* Create 2 GCs, copy the values of the first into the second */
GC gc1, gc2;
Display *display = XOpenDisplay(NULL);
Window win = XCreateSimpleWindow(etc...);
// those above both worked.
gc1 = XCreateGC(display, win, 0, NULL);
// ... some stuff done here to initialise gc1 with my defaults.
gc2= XCreateGC(display, win, 0, NULL); // is this needed??
// ok so far
XCopyGC(display, gc1, gc2, 0UL);
// ** Wham! seg fault **


Perhaps I am misusing the XCopyGC call, since gcc warns that "parameter 3
makes integer from pointer without cast." Huh? What pointer?

Also, using a 0UL for the valuemask: does that copy everything, or copy
nothing?

If I instead specify some bitmask values for valuemask instead of 0UL:
XCopyGC(display, gc1, gc2, GCForeground | GCBackground | GCFont);
I get another (new) compiler warning that parameter 4 "makes integer from
pointer without cast." Again, what pointer?

Here's the Syntax from the man page for XCreateGC and XCopyGC:
GC XCreateGC(Display *display, Drawable d, unsigned long valuemask,
XGCValues *values);
int XCopyGC(Display *display, GC src, GC dest, unsigned long valuemask);

Not a pointer in sight (except for *display). So why is gcc complaining?
Did XCreateGC actually return a pointer to a GC instead of an actual GC?
in which case, everything I did with gc1 & gc2 should be &gc1 & &gc2?

I'm clearly misreading the man page or not understanding the GC process.
If someone could help me out, much appreciate it.

Thanks,
--
NickC

Jano

unread,
Dec 4, 2009, 7:57:43 AM12/4/09
to
NickC wrote:


GC gc1, gc2 :

gc1 = XtAllocateGC (w, 0, 0, &xgc , 0, 0);
XCopyGC (dpy, gc1, 1L, gc2);

--

Jano

unread,
Dec 4, 2009, 7:59:02 AM12/4/09
to
Jano wrote:


oops...

Shoudl read gc2 = XtAlloccate..

--

NickC

unread,
Dec 4, 2009, 6:02:26 PM12/4/09
to
On Fri, 04 Dec 2009 12:57:43 +0000, "Jano wrote:

> NickC wrote:
>
>> Here's the Syntax from the man page for XCreateGC and XCopyGC:

>> GC int XCopyGC(Display *display, GC src, GC dest, unsigned long
>> valuemask);
>>
>>

> GC gc1, gc2 :
>
> gc1 = XtAllocateGC (w, 0, 0, &xgc , 0, 0);
> XCopyGC (dpy, gc1, 1L, gc2);

Thank you. I see you've reversed XCopyGC's 3rd & 4th params, and grepping
Xlib.h shows me why. I take it the man page is wrong. Are there errors in
other man pages I need to be aware of?

Thanks again,

--
NickC

Kalle Olavi Niemitalo

unread,
Dec 4, 2009, 6:05:38 PM12/4/09
to
NickC <repl...@works.fine.invalid> writes:

> Here's the Syntax from the man page for XCreateGC and XCopyGC:
> GC XCreateGC(Display *display, Drawable d, unsigned long valuemask,
> XGCValues *values);
> int XCopyGC(Display *display, GC src, GC dest, unsigned long valuemask);

The man page listed the parameters of XCopyGC in the wrong order.
It has already been fixed, so there's no need to report it again:
http://cgit.freedesktop.org/xorg/lib/libX11/commit/?id=54c64267cc8bc98641cc39a22cb7bd71673e89e0
https://bugs.launchpad.net/bugs/408337
(It's crazy though that Ubuntu wanted the lspci output and
Xorg.0.log before considering this bug.)

NickC

unread,
Dec 4, 2009, 6:59:20 PM12/4/09
to
No worries, I knew what you meant. ;)

--
NickC

NickC

unread,
Dec 4, 2009, 7:05:38 PM12/4/09
to
On Sat, 05 Dec 2009 01:05:38 +0200, Kalle Olavi Niemitalo wrote:


>
> The man page listed the parameters of XCopyGC in the wrong order.

Thanks.

My god, it actually builds and runs now! (Forgive my enthusiasm, but
after days of beating my head against a brick wall, it's easy to get
excited.)

--
NickC

AndMagicSwordToo

unread,
Dec 5, 2009, 12:59:08 PM12/5/09
to
NickC <repl...@works.fine.invalid> writes:

Mixing Xt and Xlib calls is probably not a good idea,
either, if (when) a widget fails an event it doesn't expect,
and if (when) the app runs under a window manager that
generates or propagates X protocol events in a manner it
doesn't expect. It's more reliable to use XCreateGC () if
the app is going to also use XCopyGC () and XFreeGC ().
Btw, a value mask of 0L means that

XCopyGC (dpy, gc1, 0L, gc2) == XCreateGC (dpy, w, 0L, &xgc_values)

HTH again

--
Ctalk Home Page: http://www.ctalklang.org

NickC

unread,
Dec 16, 2009, 5:59:22 AM12/16/09
to
On Sat, 05 Dec 2009 12:59:08 -0500, AndMagicSwordToo wrote:

> Mixing Xt and Xlib calls is probably not a good idea, either, if (when)
> a widget fails an event it doesn't expect, and if (when) the app runs
> under a window manager that generates or propagates X protocol events in
> a manner it doesn't expect. It's more reliable to use XCreateGC () if
> the app is going to also use XCopyGC () and XFreeGC ().

Ok, I'm using Xlib exclusively now.

> Btw, a value
> mask of 0L means that
>
> XCopyGC (dpy, gc1, 0L, gc2) == XCreateGC (dpy, w, 0L, &xgc_values)
>

Thanks, good to know.

--
NickC

0 new messages