[comp.windows.open-look] OL Flat Checkbox Widget Woes

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

kkirksey@eng.auburn.edu (Kenneth B. Kirksey) (05/30/91)

In article <1991May29.182035.26184@cbnewsm.att.com> merlyn@attunix.att.com (Steve Humphrey) writes:
>
>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

Steve,
	Thanks for the tip, but it didn't work.  I still get the bus error 
in the same place. 
	I don't think I mentioned it in my original post, but I`m running
OLIT 2.5 under X11R4 on Sun SparcStations, if it makes any difference.
				Thanx,
					Ken

+-------------------------+---------------------------------------------+
\ Ken Kirksey              \  "Genetic Drifter, Quarantined in my own    \
 \ Computer Engineering     \  dimension.                                 \
  \ Auburn University        \	Hey Look!  It Smokes! It Drinks!           \
   \                          \	  It Philosophizes!  It's Loving this new   \
    \ kkirksey@eng.auburn.edu  \    Attention!"                              \ 
     \ AOL: kkirksey1           \                    -Steve Taylor            \
      +--------------------------+---------------------------------------------+
	
	

bradst@laguna.ai.sri.com (John Bradstreet) (06/01/91)

  In regards to the problem with OL Flat Checkboxes (and flat Exclusives
and flat NonExclusives) causing core dumps on sparcs under OLIT 2.5,
I believe the problem is inside the Sun code.   Luckilly, Sun seems to be aware
of this, and seemed to have fixed the problem for the next release.  
I was experiencing the same problem myself, but I just recompiled and ran the 
example under 3.0 beta, and it worked. 

  The next question is when 3.0 is coming out for real.




--