kkirksey@eng.auburn.edu (Kenneth B. Kirksey) (05/29/91)
I'm having a terrible time using the OL flat checkbox widget. I've included at the bottom the sample program I wrote to try my hand at using the flat checkbox. When I run it as is, it gives me a bus error. When I use dbx to trace it, I get the following dump: warning: core file read error: address not in data space `FCheckBox`DrawLabel() at 0xf7731774 `FCheckBox`DrawItem() at 0xf7731c10 `Flat`Redisplay() at 0xf7738698 SendExposureEvent() at 0xf76d8d8c CompressExposures() at 0xf76d8cf8 `Event`DispatchEvent() at 0xf76d88cc DecideToDispatch() at 0xf76d913c XtDispatchEvent() at 0xf76d92f4 XtAppMainLoop() at 0xf76d95cc XtMainLoop() at 0xf76d95ac main(argc = 1, argv = 0xf7fffc7c), line 81 in "/home/u2/jstrang/cost/src/FlatTest.c" (dbx) What am I doing wrong? This code is pretty much the sample code given on pages 180-183 of _An Open Look At Unix_. If anyone out there has had this problem before, or if anyone can tell me what I'm doing wrong, you would have my undying gratitude. Thanx in advance, Ken --------------Cut Here------------------------------------------------------- #include <X11/Intrinsic.h> #include <X11/StringDefs.h> #include <Xol/OpenLook.h> #include <Xol/FCheckBox.h> #include <strings.h> #include <stdio.h> static String itemFields[] = { XtNlabel }; #define NUM_ITEM_FIELDS 1 typedef struct _Item { String label; } Item; Arg args[12]; int n; static Item items[] = { {"CSE100"}, {"foo"}, {"foo"}, {"foo"}, {"CSE120"}, {"foo"}, {"foo"}, {"foo"}, {"CSE200"}, {"foo"}, {"foo"}, {"foo"}, {"CSE2200"}, {"foo"}, {"foo"}, {"foo"} }; #define NUM_ITEMS 16 Widget toplevel, rs_flat_checkbox; main (argc, argv) int argc; char **argv; { /*-----------------------------------------------------------------------+ | Initialize Top Level Shell | +-----------------------------------------------------------------------*/ toplevel = OlInitialize ( "flatTest", "FlatTest", NULL, 0, &argc, argv); n = 0; XtSetArg (args[n], XtNlayoutType, OL_FIXEDCOLS); n++; XtSetArg (args[n], XtNmeasure, 4); n++; XtSetArg (args[n], XtNitems, items); n++; XtSetArg (args[n], XtNnumItems, NUM_ITEMS); n++; XtSetArg (args[n], XtNitemFields, itemFields); n++; XtSetArg (args[n], XtNnumItemFields, NUM_ITEM_FIELDS); n++; XtSetArg (args[n], XtNlabelJustify, OL_RIGHT); n++; rs_flat_checkbox = XtCreateManagedWidget( "rs_flat_checkbox", flatCheckBoxWidgetClass, toplevel, args, n); /*-----------------------------------------------------------------------+ | Go To It ............... | +-----------------------------------------------------------------------*/ XtRealizeWidget (toplevel); XtMainLoop(); }
merlyn@attunix.att.com (Steve Humphrey) (05/30/91)
> I'm having a terrible time using the OL flat checkbox widget. I've > included at the bottom the sample program I wrote to try my hand at using > the flat checkbox. When I run it as is, it gives me a bus error. > I use dbx to trace it, I get the following dump: > warning: core file read error: address not in data space > `FCheckBox`DrawLabel() at 0xf7731774 > ... > > typedef struct _Item > { > String label; > } Item; > > static Item items[] = { > {"CSE100"}, > ... > > n = 0; > XtSetArg (args[n], XtNitems, items); n++; > XtSetArg (args[n], XtNnumItems, NUM_ITEMS); n++; > > rs_flat_checkbox = XtCreateManagedWidget( > "rs_flat_checkbox", > flatCheckBoxWidgetClass, > toplevel, > args, n); > ... I tried your code exactly as sent; it works fine on my '386 running the OPEN LOOK 4.0 toolkit (equivalent to the OpenWindows 2.5 OLIT). I have not tried it yet on a Sun. However, the problem MAY be in the definition of the Item structure. Now the ``Open Look at UNIX'' book has exactly the same problem, and I thought John Miller tested his examples on a Sun, so something else may be wrong. The XtNitems resource takes an array of items, each of which is defined by a structure of XtArgVal's. This parallels the way attributes are passed in regular XtCreateWidget or XtSetValues calls, for exactly the same reason: The widgets (or Intrinsics) do not know a priori the type of each value, thus the values must be coerced to a common type for passing from the client to the widget. So the correct code fragment from the above should be: > typedef struct _Item > { > XtArgVal label; > } Item; > > static Item items[] = { > { (XtArgVal)"CSE100" }, > ... XtArgVal is defined as a "long" on Suns, versus the "char*" definition of String. Now I would think this would be OK, but I'm not familiar with native types of a SPARC chip. Even if it turns out this is not the problem at hand, I suggest using the XtArgVal type in the definition of the XtNitems array's structure. Eventually this *will* save you a core dump. Steve Humphrey UNIX System Laboratories