Bug 13956 - simple program crashes when closing windows
Summary: simple program crashes when closing windows
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: Lib/Xt (show other bugs)
Version: 7.1 (2006.05)
Hardware: x86 (IA32) Linux (All)
: medium critical
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
URL:
Whiteboard:
Keywords: NEEDINFO
Depends on:
Blocks:
 
Reported: 2008-01-07 11:02 UTC by sinclairjw
Modified: 2010-12-15 06:56 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description sinclairjw 2008-01-07 11:02:43 UTC
Build and execute the following c program. The first window gives a menu
to open a 2nd window. The 2nd window gives a menu to exit (close the
2nd window). Failure occurs while closing the 2nd window eventually.
Failure usually occurs within 20 open/close sequences but occasionally
it takes more than 20.

makefile is
===================================================
CFLAGS = -Wall -O0 -g
LDFLAGS = -g

all : 1

1 : 1.o
        g++ $(LDFLAGS) -o 1 \
        -L/usr/X11R6/lib \
        -lXm -lXt -lX11 \
        1.o

1.o : 1.c
        cc $(CFLAGS) -o 1.o -c 1.c
=================================================================

c code is
==================================================================
/* ---------------------------------------------
 *
 * This application creates a main window and raises it
 * approximately every 3 seconds. The only menu option
 * is "exit".
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <wait.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>

#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include <Xm/Protocols.h>
#include <Xm/MainW.h>
#include <Xm/PushB.h>
#include <Xm/CascadeB.h>
#include <Xm/RowColumn.h>

static int g_exit = 0;
XtAppContext app;
Display *display;
Widget widgetToKill = NULL;

void exit_cb (
  Widget w,
  XtPointer client,
  XtPointer call )
{

int *flag = (int *) client;

  printf( "exit_cb callback function was invoked\n" );

  *flag = 1;

}

void exitOne_cb (
  Widget w,
  XtPointer client,
  XtPointer call )
{

  printf( "exitOne_cb callback function was invoked\n" );

  do {
    widgetToKill = w;
    w = XtParent( w );
  } while ( w );

}

void newWin_cb (
  Widget w,
  XtPointer client,
  XtPointer call )
{

Widget appTop1, mainWin1, menuBar1, filePullDown1, fileCascade1, exitB1;
XmString menuStr, str;
Atom wm_delete_window;

  appTop1 = XtVaAppCreateShell( NULL, "test", applicationShellWidgetClass,
   display,
   XmNiconic, False,
   XmNmappedWhenManaged, True,
   NULL );

  mainWin1 = XtVaCreateManagedWidget( "main", xmMainWindowWidgetClass,
   appTop1,
   XmNscrollBarDisplayPolicy, XmAS_NEEDED,
   XmNscrollingPolicy, XmAUTOMATIC,
   NULL );

  menuBar1 = XmCreateMenuBar( mainWin1, "menubar", NULL, 0 );

  filePullDown1 = XmCreatePulldownMenu( menuBar1, "file", NULL, 0 );

  menuStr = XmStringCreateLocalized( "file" );
  fileCascade1 = XtVaCreateManagedWidget( "filemenu", xmCascadeButtonWidgetClass
,
   menuBar1,
   XmNlabelString, menuStr,
   XmNmnemonic, 'f',
   XmNsubMenuId, filePullDown1,
   NULL );
  XmStringFree( menuStr );

  str = XmStringCreateLocalized( "exit" );
  exitB1 = XtVaCreateManagedWidget( "pb", xmPushButtonWidgetClass,
   filePullDown1,
   XmNlabelString, str,
   NULL );
  XmStringFree( str );
  XtAddCallback( exitB1, XmNactivateCallback, exitOne_cb,
   (XtPointer) &g_exit );

  XtManageChild( menuBar1 );

  XtRealizeWidget( appTop1 );

  wm_delete_window = XmInternAtom( display, "WM_DELETE_WINDOW", False );
  XmAddWMProtocolCallback( appTop1, wm_delete_window,
   exitOne_cb, (XtPointer) &g_exit );
  XtVaSetValues( appTop1, XmNdeleteResponse, XmDO_NOTHING, NULL );

}

int main (
  int argc,
  char **argv
) {

Widget appTop, mainWin, menuBar, filePullDown, fileCascade, exitB;
XmString menuStr, str;
XEvent Xev;
int result, isXEvent, n, count;
struct timespec req, rem;
Atom wm_delete_window;

  XtToolkitInitialize();
  app = XtCreateApplicationContext();

  display = XtOpenDisplay( app, NULL, NULL, "test", NULL, 0, &argc,
   argv );

  appTop = XtVaAppCreateShell( NULL, "test", applicationShellWidgetClass,
   display,
   XmNiconic, False,
   XmNmappedWhenManaged, True,
   NULL );

  mainWin = XtVaCreateManagedWidget( "main", xmMainWindowWidgetClass,
   appTop,
   XmNscrollBarDisplayPolicy, XmAS_NEEDED,
   XmNscrollingPolicy, XmAUTOMATIC,
   NULL );

  menuBar = XmCreateMenuBar( mainWin, "menubar", NULL, 0 );

  filePullDown = XmCreatePulldownMenu( menuBar, "file", NULL, 0 );

  menuStr = XmStringCreateLocalized( "file" );
  fileCascade = XtVaCreateManagedWidget( "filemenu", xmCascadeButtonWidgetClass,
   menuBar,
   XmNlabelString, menuStr,
   XmNmnemonic, 'f',
   XmNsubMenuId, filePullDown,
   NULL );
  XmStringFree( menuStr );

  str = XmStringCreateLocalized( "new" );
  exitB = XtVaCreateManagedWidget( "pb", xmPushButtonWidgetClass,
   filePullDown,
   XmNlabelString, str,
   NULL );
  XmStringFree( str );
  XtAddCallback( exitB, XmNactivateCallback, newWin_cb,
   (XtPointer) &g_exit );

  XtManageChild( menuBar );

  XtRealizeWidget( appTop );

  wm_delete_window = XmInternAtom( display, "WM_DELETE_WINDOW", False );
  XmAddWMProtocolCallback( appTop, wm_delete_window,
   exit_cb, (XtPointer) &g_exit );
  XtVaSetValues( appTop, XmNdeleteResponse, XmDO_NOTHING, NULL );

  //-------------------------------------------

  n = 0;

  while ( !g_exit ) {

    count = 1000;

    do {
      result = XtAppPending( app );
      if ( result ) {
        isXEvent = XtAppPeekEvent( app, &Xev );
        if ( isXEvent ) {
          if ( Xev.type != Expose ) {
            XtAppProcessEvent( app, result );
          }
          else {
            XtAppProcessEvent( app, result );
          }
        }
        else { // process all timer or alternate events
          XtAppProcessEvent( app, result );
        }
      }
      count--;
    } while ( result && count );

    req.tv_sec = 0;
    req.tv_nsec = 100000000;
    nanosleep( &req, &rem );

    // raise window approx every 3 seconds
    n++;
    if ( n == 30 ) {
      n = 0;
      printf( "call XRaiseWindow\n" );
      XRaiseWindow( display, XtWindow(appTop) );
    }

    if ( widgetToKill ) {
      XtDestroyWidget( widgetToKill );
      widgetToKill = NULL;
    }

  }

  return 0;

}
==========================================================
Comment 1 Jesse Adkins 2010-12-10 15:32:01 UTC
Using xserver 1.9 and libXt 1.0.9, I receive this message :

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  19 (X_DeleteProperty)
  Resource id in failed request:  0x0
  Serial number of failed request:  85
  Current serial number in output stream:  89

Do you see this error (or something similar) with a newer libXt?
Comment 2 sinclairjw 2010-12-15 06:56:04 UTC
I no longer see this problem - 12/15/2010


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.