LECTURE 14 ¥¨¥é¡¼¥¤¥Ù¥ó¥È

¡û ¤Ï¤¸¤á¤Ë

X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¥¨¥é¡¼¤â¥¤¥Ù¥ó¥È¤È¤·¤Æ¥¯¥é¥¤¥¢¥ó¥È¤ËÄÌÃΤµ¤ì¤Þ¤¹¡£¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã¤ò½ªÎ»¤µ¤»¤Æ X ¥¦¥£¥ó¥É¥¦¤«¤éÈ´¤±¤Æ¥³¥ó¥½¡¼¥ë¤ËÌá¤Ã¤¿¤È¤­¤Ë¡¢Bad Drawable ... ¤È¤«¤Ê¤ó¤È¤«¤¤¤¦¤¤¤«¤Ë¤â¥¨¥é¡¼¤Ã¤Ý¤¤É½¼¨¤ò¸«¤¿¤³¤È¤¬¤¢¤ê¤Þ¤»¤ó¤«? (¤¦¤Á¤Ç¤Ï²¿¤À¤«¤·¤ç¤Ã¤Á¤å¤¦É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹)¡£¤³¤ì¤é¤Îɽ¼¨¤Ï¡¢X ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¥¨¥é¡¼¤¬À¸¤¸¤¿·ë²Ì¥¨¥é¡¼¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤Æ¤½¤ÎÆâÍƤ¬É½¼¨¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¤¹¡£

¤³¤³¤Ç¤Ï¥¨¥é¡¼¥¤¥Ù¥ó¥È¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£

¡û ¥¨¥é¡¼¥¤¥Ù¥ó¥È¤¬µ¯¤­¤ë¸¶°ø

¥¨¥é¡¼¥¤¥Ù¥ó¥È¤Ë¤Ï¡¢¥¦¥£¥ó¥É¥¦¤òÀ¸À®¤·¤è¤¦¤È¤·¤¿¤¬¥á¥â¥êÉÔ­¤Ê¤É¤Ë¤è¤Ã¤ÆÀ¸À®¤Ë¼ºÇÔ¤·¤¿¡¢À¸À®¤·¤Æ¤¤¤Ê¤¤¥¦¥£¥ó¥É¥¦¤ËÂФ·¤ÆÉÁ²è¤·¤è¤¦¤È¤·¤¿¡¢¤È¤¤¤Ã¤¿¾ì¹ç¤Ë¤½¤ì¤ò Xlib ¤¬¸¡½Ð¤·¤ÆȯÀ¸¤¹¤ë¤â¤Î¤È¡¢Xlib ¤ä X ¥µ¡¼¥ÐÆâ¤Ç¼Â¹Ô¤·¤¿¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬¥¨¥é¡¼¤È¤Ê¤Ã¤¿¾ì¹ç¤ËȯÀ¸¤¹¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤¹¡£

¤³¤ì¤é¤Î¥¨¥é¡¼¤¬À¸¤¸¤ë¤È¥¨¥é¡¼¥¤¥Ù¥ó¥È¤È¤·¤Æ¥¯¥é¥¤¥¢¥ó¥È¤ËÅÁ¤ï¤ê¤Þ¤¹¤¬¡¢Ä̾ï¤Î¥¤¥Ù¥ó¥È¤È°Û¤Ê¤ê Xlib ¤Ë¤¢¤é¤«¤¸¤áÁȤ߹þ¤Þ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é¤Ç½èÍý¤µ¤ì¤Þ¤¹¡£¤³¤Î¥¨¥é¡¼¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é¤Ï¡¢¥¤¥Ù¥ó¥È¤ò²òÀϤ·¥¨¥é¡¼¾ðÊó¤òɽ¼¨¤·¤Æ¥×¥í¥°¥é¥à¤ò½ªÎ»¤µ¤»¤Þ¤¹

¥¨¥é¡¼¥¤¥Ù¥ó¥È¾ðÊó¤Ï XErrorEvent ¹½Â¤ÂΤËÀßÄꤵ¤ì¤Æ¡¢¥¨¥é¡¼¥Ï¥ó¥É¥é¤ËÅϤµ¤ì¤Þ¤¹¡£

typedef struct 
{
  int           type;         
  Display*      display;       /* ¥¤¥Ù¥ó¥È¤¬ÆɤߤÀ¤µ¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤ */
  unsigned long serial;        /* ¼ºÇÔ¤·¤¿¥ê¥¯¥¨¥¹¥È¤Î¥·¥ê¥¢¥ëÈÖ¹æ */
  unsigned char error_code;    /* ¼ºÇÔ¤·¤¿¥ê¥¯¥¨¥¹¥È¤Î¥¨¥é¡¼¥³¡¼¥É */
  unsigned char request_code;  /* ¼ºÇÔ¤·¤¿¥ê¥¯¥¨¥¹¥È¤Î¥á¥¸¥ã¡¼¥ª¥Ú¥³¡¼¥É */
  unsigned char minor_code;    /* ¼ºÇÔ¤·¤¿¥ê¥¯¥¨¥¹¥È¤Î¥Þ¥¤¥Ê¡¼¥ª¥Ú¥³¡¼¥É */
  XID           resourceid;    /* ¥ê¥½¡¼¥¹ID */
} XErrorEvent;

¤¤¤¯¤Ä¤«¤Î¥¨¥é¡¼¥¤¥Ù¥ó¥È¤ò²¼É½¤Ë¼¨¤·¤Þ¤¹(Á´¤Æ¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó)¡£

¥¨¥é¡¼¥¤¥Ù¥ó¥ÈÄê¿ô̾ÀâÌÀ
BadAlloc Í×µá¥ê¥½¡¼¥¹¤Î³ä¤êÅö¤Æ¤Ë¼ºÇÔ
BadCursor ¥Ñ¥é¥á¡¼¥¿¤¬¥«¡¼¥½¥ë¤Ç¤Ï¤Ê¤¤
BadDrawable ¥Ñ¥é¥á¡¼¥¿¤¬ Drawable ¤Ç¤Ê¤¤
BadFont ¥Ñ¥é¥á¡¼¥¿¤¬¥Õ¥©¥ó¥È¤Ç¤Ï¤Ê¤¤
BadGC ¥Ñ¥é¥á¡¼¥¿¤¬ GC ¤Ç¤Ï¤Ê¤¤
BadImplementationX ¥µ¡¼¥Ð¤Ë·ç´Ù¤¬¤¢¤ë
BadMatch ¥Ñ¥é¥á¡¼¥¿¤Î¥ß¥¹¥Þ¥Ã¥Á
BadName ¥Õ¥©¥ó¥È̾¤«¥«¥é¡¼Ì¾¤¬Â¸ºß¤·¤Ê¤¤
BadPixmap ¥Ñ¥é¥á¡¼¥¿¤¬¥Ô¥¯¥¹¥Þ¥Ã¥×¤Ç¤Ï¤Ê¤¤
BadValue À°¿ô¥Ñ¥é¥á¡¼¥¿¤¬Èϰϳ°
BadWindow ¥Ñ¥é¥á¡¼¥¿¤¬¥¦¥£¥ó¥É¥¦¤Ç¤Ï¤Ê¤¤

¡û ¥¨¥é¡¼¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é¤ÎÊѹ¹

Xlib ¤¬Ä󶡤·¤Æ¤¤¤ë¥Ç¥Õ¥©¥ë¥È¤Î¥¨¥é¡¼¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é¤Ï¡¢¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤·¤Æ¥×¥í¥°¥é¥à¤ò½ªÎ»¤µ¤»¤Æ¤·¤Þ¤¤¤Þ¤¹¡£¤³¤ì¤ËÂФ·¤ÆÆȼ«¤Î½ªÎ»½èÍý¤ò¹Ô¤Ã¤¿¤ê¡¢¥×¥í¥°¥é¥à¤ÎÆ°ºî¤ò·Ñ³¤µ¤»¤ë¤¿¤á¤Ë¼«ºî¤Î¥¨¥é¡¼¥Ï¥ó¥É¥é¤ò¿·¤¿¤ËÅÐÏ¿¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤½¤ì¤Ë¤Ï XSetErrorHandler() ¤ò»È¤¤¤Þ¤¹¡£

int XSetErrorHandler( int ( *handler )(Display*, XErrorEvent* ) );

handler : ¼«ºî¥¨¥é¡¼¥Ï¥ó¥É¥é¤Ø¤Î´Ø¿ô¥Ý¥¤¥ó¥¿

»ØÄꤷ¤¿ handler ¤¬¿·¤·¤¤¥¨¥é¡¼¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é¤È¤·¤ÆÅÐÏ¿¤µ¤ì¤Þ¤¹¡£handler ¤Ë NULL ¤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤Ï¥Ç¥Õ¥©¥ë¥È¤Î¥Ï¥ó¥É¥é¤¬ºÆÀßÄꤵ¤ì¤Þ¤¹¡£

Î㤨¤Ð LECTURE 5 ¤Î xgraphics.c ¤Î»Í³Ñ·Á¤òÉÁ²è¤·¤Æ¤¤¤ëÉôʬ¤Î¥³¡¼¥É¤ò

/* »Í³Ñ·Á¤ÎÉÁ²è */
XFillRectangle( dpy, ( Window )gc, gc, BOX_X, BOX_Y, BOX_W, BOX_H );

¤È½ñ¤­´¹¤¨¤Æ̵Íý¤ä¤ê¼Â¹Ô¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤Ê¥¨¥é¡¼½ÐÎϤ¬É½¼¨¤µ¤ì¤Æ¥×¥í¥°¥é¥à¤¬½ªÎ»¤·¤Æ¤·¤Þ¤¤¤Þ¤¹¡£

X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  70 (X_PolyFillRectangle)
  Resource id in failed request:  0x804b180
  Serial number of failed request:  17
  Current serial number in output stream:  19

¤³¤Îɽ¼¨ÆâÍƤòÊѤ¨¤ë¤¿¤á¡¢¼¡¤Î¤è¤¦¤Ê´Ø¿ô my_handler() ¤òºîÀ®¤·¤Æ¡¢¿·¤·¤¤¥¨¥é¡¼¥Ï¥ó¥É¥é¤È¤·¤ÆÀßÄꤷ¤Þ¤¹¡£

int my_handler( Display* dpy, XErrorEvent* event )
{
    printf( "Now I have to go...\n" );
    exit( 1 );
}

XSetErrorHandler( my_handler );

¤½¤Î¸åºÆÅټ¹Ԥ¹¤ë¤È¡¢²èÌ̤Ë

Now I have to go...

¤Èɽ¼¨¤¬ÊѤï¤ë¤Î¤¬³Îǧ¤Ç¤­¤Þ¤¹(¤ä¤Ã¤Ñ¤ê½ªÎ»¤·¤Þ¤¹¤¬(^_^;) ¤Á¤Ê¤ß¤Ë¥µ¥ó¥×¥ë¥½¡¼¥¹¥³¡¼¥É¤Ï xerr.c ¤Ç¤¹ )¡£¤Ê¤ª¡¢XEvent ¹½Â¤ÂΤΠerror_code ¤òÄ´¤Ù¤ë¤³¤È¤Ç¡¢¥¨¥é¡¼¤Î¼ïÎà¤Ë±þ¤¸¤¿¥¨¥é¡¼½èÍý¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¸Ä¿ÍŪ¤Ë¤Ï¡¢°ìÈÌŪ¤Ê X ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ë¤ª¤¤¤Æ¤É¤³¤Þ¤Ç¥¨¥é¡¼¥Ï¥ó¥É¥é¤Ë¤è¤ë½èÍý¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë¤Î¤«¡¢¤¤¤í¤¤¤íÄ´¤Ù¤Æ¤ß¤¿¤¤¤È»×¤Ã¤Æ¤Þ¤¹¡£