Scorpio EGBB Segfault

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

EvgeniyZh
Posts: 43
Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel

Scorpio EGBB Segfault

Post by EvgeniyZh »

I'm trying to add Scorpio EGBB support to engine.
Here is code for loading:

Code: Select all

static void load_egbb_library() {
	 HMODULE hmod;
	 __PLOAD_EGBB __load_egbb;
	 const char* main_path = option_get("Bitbase Path");
	 uint32_t egbb_cache_size = option_get_int("Bitbase Cache Size");

	 char path[256];
	 strcpy(path, main_path);
	 strcat(path, EGBB_NAME);
	 if (hmod)
		FreeLibrary(hmod);
	 if(hmod = LoadLibrary(path)) {
		__load_egbb = (__PLOAD_EGBB) GetProcAddress(hmod,"load_egbb_xmen");
		__probe_egbb = (__PROBE_EGBB) GetProcAddress(hmod,"probe_egbb_xmen");
		__load_egbb(main_path, egbb_cache_size, egbb_load_type);
		egbb_is_loaded = 1;
		printf("Bitbase loaded\n");
	 } else {
		//printf( "%d\n",GetLastError());
		egbb_is_loaded = 0;
		printf("Bitbase not loaded\n");
	 }
}
for probing:

Code: Select all

    if (egbb_is_loaded && (mat_info->flags & MatBitbaseFlag) != 0) {

        const sq_t *ptr;
        int32_t from;
        int32_t score;


		for &#40;from=0; from < 64; ++from&#41; &#123;
			if &#40;board->square&#91;SQUARE_FROM_64&#40;from&#41;&#93; == Empty&#41; continue;
			
			switch &#40;board->square&#91;SQUARE_FROM_64&#40;from&#41;&#93;) &#123;
				case WP&#58; ADD_PIECE&#40;WPawn&#41;; break;
				case BP&#58; ADD_PIECE&#40;BPawn&#41;; break;
				case WN&#58; ADD_PIECE&#40;WKnight&#41;; break;
				case BN&#58; ADD_PIECE&#40;BKnight&#41;; break;
				case WB&#58; ADD_PIECE&#40;WBishop&#41;; break;
				case BB&#58; ADD_PIECE&#40;BBishop&#41;; break;
				case WR&#58; ADD_PIECE&#40;WRook&#41;; break;
				case BR&#58; ADD_PIECE&#40;BRook&#41;; break;
				case WQ&#58; ADD_PIECE&#40;WQueen&#41;; break;
				case BQ&#58; ADD_PIECE&#40;BQueen&#41;; break;
				case WK&#58; egbb_square&#91;0&#93; = from; break;
				case BK&#58; egbb_square&#91;1&#93; = from; break;
				default&#58; break;
			&#125;
			
		&#125;

        ++tbhits;

        score = __probe_egbb&#40;player, egbb_piece, egbb_square&#41;;
		if&#40;score != NotFound&#41; &#123;
			if &#40;score == 0&#41; &#123;
				return ValueDraw;
			&#125; else &#123;
				return score;
			&#125;
		&#125;
	&#125;
Using version 4.1 x64, everyting is loads OK, but while trying to probe I get segmentation fault in

Code: Select all

score = __probe_egbb&#40;player, egbb_piece, egbb_square&#41;;
What could the problem be?
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Scorpio EGBB Segfault

Post by Ferdy »

Where is the declaration of egbb_piece and egbb_square? Can you also show your ADD_PIECE() routine?
EvgeniyZh
Posts: 43
Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel

Re: Scorpio EGBB Segfault

Post by EvgeniyZh »

Ferdy wrote:Where is the declaration of egbb_piece and egbb_square? Can you also show your ADD_PIECE() routine?
of course all variables are declared:

Code: Select all



	int32_t total_pieces;
	int32_t player;
	//int32_t w_ksq;
	//int32_t b_ksq;
	int32_t egbb_piece&#91;MAX_PIECES&#93;;
	int32_t egbb_square&#91;MAX_PIECES&#93;;
	
	player = board->turn; 
	total_pieces = 2;
    for &#40;int32_t i = 0; i < MAX_PIECES; ++i&#41; &#123;
        egbb_piece&#91;i&#93; = 0;
        egbb_square&#91;i&#93; = 0;
    &#125;
	egbb_piece&#91;0&#93; = WKing;
	egbb_piece&#91;1&#93; = BKing;
and:

Code: Select all

#define ADD_PIECE&#40;type&#41; &#123;\
	    egbb_piece&#91;total_pieces&#93; = type;\
	    egbb_square&#91;total_pieces&#93; = from;\
        ++total_pieces;\
&#125;;
While debugging I checked the parameters and I'm pretty sure they are OK: variable for side and two arrays with type of piece and square it's placed.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Scorpio EGBB Segfault

Post by Ferdy »

Which egbb files did you use, be sure you are using the new ones.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Scorpio EGBB Segfault

Post by Ferdy »

EvgeniyZh wrote:
Ferdy wrote:Where is the declaration of egbb_piece and egbb_square? Can you also show your ADD_PIECE() routine?
of course all variables are declared:

Code: Select all



	int32_t total_pieces;
	int32_t player;
	//int32_t w_ksq;
	//int32_t b_ksq;
	int32_t egbb_piece&#91;MAX_PIECES&#93;;
	int32_t egbb_square&#91;MAX_PIECES&#93;;
	
	player = board->turn; 
	total_pieces = 2;
    for &#40;int32_t i = 0; i < MAX_PIECES; ++i&#41; &#123;
        egbb_piece&#91;i&#93; = 0;
        egbb_square&#91;i&#93; = 0;
    &#125;
	egbb_piece&#91;0&#93; = WKing;
	egbb_piece&#91;1&#93; = BKing;
and:

Code: Select all

#define ADD_PIECE&#40;type&#41; &#123;\
	    egbb_piece&#91;total_pieces&#93; = type;\
	    egbb_square&#91;total_pieces&#93; = from;\
        ++total_pieces;\
&#125;;
While debugging I checked the parameters and I'm pretty sure they are OK: variable for side and two arrays with type of piece and square it's placed.
Looks fine so far.
EvgeniyZh wrote:of course all variables are declared:
Those are arrays I want to see its size. They are not shown in your first post. What is the value of this MAX_PIECES?

Do you have a chess position where seg-fault is triggered?
Also make sure you follow the board representation of egbb probing.
EvgeniyZh
Posts: 43
Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel

Re: Scorpio EGBB Segfault

Post by EvgeniyZh »

Ferdy wrote:Do you have a chess position where seg-fault is triggered?
I'm pretty sure it fails any time it calls the function. For example:

Code: Select all

2R5/8/8/4k3/8/8/6K1/8 w - -
Ferdy wrote:Those are arrays I want to see its size. They are not shown in your first post. What is the value of this MAX_PIECES?

Code: Select all

const int16_t MAX_PIECES = 32;
Ferdy wrote:Also make sure you follow the board representation of egbb probing.
Well the variable values are legal(pieces 1,7 for kings, and 3 for piece, square value <64, player is 0 or 1), so even if there is some mistake there shouldn't be segfault.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Scorpio EGBB Segfault

Post by Ferdy »

That is all from me for now.
One more thing, use the latest egbb files. Try the latest 4-men here for example. But use the latest egbbdll.
https://sites.google.com/site/dshawul/home
EvgeniyZh
Posts: 43
Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel

Re: Scorpio EGBB Segfault

Post by EvgeniyZh »

Ferdy wrote:That is all from me for now.
One more thing, use the latest egbb files. Try the latest 4-men here for example. But use the latest egbbdll.
https://sites.google.com/site/dshawul/home
Yeah, I'm using latest ones, exactly from this site.

The exact values are:
egbb_piece == [1,7,3,0....]
egbb_square == [5, 36, 58, 0......]
player == 1
fridokar
Posts: 9
Joined: Thu Dec 04, 2014 2:14 pm

Re: Scorpio EGBB Segfault

Post by fridokar »

For "probe_egbb_xmen" treat the kings like the other pieces. Try:

Code: Select all

case WK&#58; ADD_PIECE&#40;WKing&#41;; break;
case BK&#58; ADD_PIECE&#40;BKing&#41;; break;
EvgeniyZh
Posts: 43
Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel

Re: Scorpio EGBB Segfault

Post by EvgeniyZh »

fridokar wrote:For "probe_egbb_xmen" treat the kings like the other pieces. Try:

Code: Select all

case WK&#58; ADD_PIECE&#40;WKing&#41;; break;
case BK&#58; ADD_PIECE&#40;BKing&#41;; break;
That's worked! Thanks a lot!