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:
// 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 );
}
}