Problems in Android build

Discussion of chess software programming and technical issues.

Moderator: Ras

mkchan
Posts: 88
Joined: Thu Oct 06, 2016 9:17 pm
Location: India

Problems in Android build

Post by mkchan »

Hi all,
I had compiled WyldChess for android in the past and had a few problems. I believe I've fixed them but I still have a few doubts.
Take the following code:

Code: Select all

unsigned long long curr_time()
{
	static struct timeval curr;
	gettimeofday(&curr, 0);
	return (curr.tv_sec * 1000 + (curr.tv_usec / 1000.0));
}
This code works fine in Linux and Windows(x86-64) but always produces 0 when running on my Android phone and with a Raspberry Pi 3 causing an infinite search. I compiled for both on the Rpi 3 itself(statically linked).
Replacing it with the following fixes it on the 2 devices and works well with Windows/Linux too:

Code: Select all

struct timeval start_time;

void init_timer()
{
	gettimeofday(&start_time, 0);
}

unsigned long long curr_time()
{
	static struct timeval curr;
	gettimeofday(&curr, 0);
	return ((curr.tv_sec - start_time.tv_sec) * 1000 + ((curr.tv_usec - start_time.tv_usec) / 1000.0));
}
I fail to understand why because according to the man-pages for gettimeofday():

Code: Select all

The gettimeofday() function shall obtain the current time, expressed as
       seconds  and  microseconds since the Epoch, and store it in the timeval
       structure pointed to by tp.  The resolution  of  the  system  clock  is
       unspecified.
mkchan
Posts: 88
Joined: Thu Oct 06, 2016 9:17 pm
Location: India

Re: Problems in Android build

Post by mkchan »

Another interesting thing to note for WyldChess on android is that it works in XBoard mode with Chess for Android by Aart J.C. Bik and not in UCI mode. Which is funny because it seems to work just fine in DroidFish(which i believe only runs on UCI mode)
abulmo2
Posts: 489
Joined: Fri Dec 16, 2016 11:04 am
Location: France
Full name: Richard Delorme

Re: Problems in Android build

Post by abulmo2 »

mkchan wrote:Hi all,

Code: Select all

	return (curr.tv_sec * 1000 + (curr.tv_usec / 1000.0));
I would try this:

Code: Select all

	return curr.tv_sec * 1000ULL + curr.tv_usec / 1000;
Richard Delorme