Skip navigation.
Home
The QNX Community Portal

View topic - Segmentation Fault during PtSetResource()

Segmentation Fault during PtSetResource()

Isn't the name clear?

Segmentation Fault during PtSetResource()

Postby Ginosaji » Wed May 04, 2011 6:01 am

We're trying to get a chess game running on an Atmel AT91SAM9G45-EKES evaluation board. The only thing standing in the way of a completed project right now is this seemingly random segmentation fault.

The code below is part of our callback for button presses. The first time this is ran, everything works fine: the button images are updated and displayed perfectly. The second time this code is ran, however, the last PtSetResource() call throws a segmentation fault.

Offending code snippet:
Code: Select all
   // couldn't find a cleaner way to do this
   int row;
   int col;
   int piece;

   for ( row = 0 ; row < 8 ; row++ )
   {
      for ( col = 0 ; col < 8 ; col++ )
      {
         button = AbGetABW (row*8+col+1);
         piece = getPiece ( row , col );
         PtSetResource ( button , Pt_ARG_LABEL_TYPE , Pt_IMAGE , 0 );
         if ( piece == BROOK )
            label = ABW_blkRook;
         else if ( piece == BKNIGHT )
            label = ABW_blkKnight;
         else if ( piece == BBISHOP )
            label = ABW_blkBishop;
         else if ( piece == BPAWN )
            label = ABW_blkPawn;
         else if ( piece == BKING )
            label = ABW_blkKing;
         else if ( piece == BQUEEN )
            label = ABW_blkQueen;
         else if ( piece == WROOK )
            label = ABW_whtRook;
         else if ( piece == WKNIGHT )
            label = ABW_whtKnight;
         else if ( piece == WBISHOP )
            label = ABW_whtBishop;
         else if ( piece == WPAWN )
            label = ABW_whtPawn;
         else if ( piece == WKING )
            label = ABW_whtKing;
         else if ( piece == WQUEEN )
            label = ABW_whtQueen;
         else
         {
            PtSetResource ( button , Pt_ARG_LABEL_TYPE , Pt_Z_STRING , 0 );
            continue;
         }

         PtGetResource ( label , Pt_ARG_LABEL_IMAGE , &image , 0 );
         PtSetResource ( button , Pt_ARG_LABEL_IMAGE , image , 0 );
      }
   }
Ginosaji
New Member
 
Posts: 3
Joined: Wed May 04, 2011 5:48 am

RE: Segmentation Fault during PtSetResource()

Postby Ginosaji » Wed May 04, 2011 6:08 am

If I were to take a wild guess, I think it's because PhReleaseImage() is being called behind the scenes. Is there a flag I can set to prevent my images from being released? I'm trying to reuse them by stealing them from some hidden labels.
Ginosaji
New Member
 
Posts: 3
Joined: Wed May 04, 2011 5:48 am

RE: Segmentation Fault during PtSetResource()

Postby Ginosaji » Wed May 04, 2011 6:45 am

My wild guess seems to have been correct. I stopped borrowing the images from the labels and just loaded them from files with PxLoadImag() as needed and the fault has gone away. Just need to sort out the transparency colours now.
Ginosaji
New Member
 
Posts: 3
Joined: Wed May 04, 2011 5:48 am

RE: Segmentation Fault during PtSetResource()

Postby maschoen » Wed May 04, 2011 12:53 pm

I don't know if this is related but I found a peculiar bug having to do with loading images from a picture module.
The images were originally .PNG's loaded into a label widget. If they had transparency they did not load properly from the picture module, however it they didn't have transparency they did load properly.

My kludgy solution was to not load the images from the picture module. Instead I put the labels on the main window, but with X,Y coordinates off the visible part. I was able to load images from these labels without any problem. So what is special about a picture module + transparency PNG?
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 1 guest