mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
fix failure to save when exiting, e.g. by pressing Home when when a
blocking dialog is up, by always saving on exiting the jni loop instead of exiting after pushing a SAVE event which was getting dropped.
This commit is contained in:
parent
8d9aa5ae0e
commit
c8c1fe6f70
2 changed files with 35 additions and 20 deletions
|
@ -1332,11 +1332,7 @@ public class BoardActivity extends XWActivity
|
||||||
interruptBlockingThread();
|
interruptBlockingThread();
|
||||||
|
|
||||||
if ( null != m_jniThread ) {
|
if ( null != m_jniThread ) {
|
||||||
if ( save ) {
|
m_jniThread.waitToStop( save );
|
||||||
Utils.logf( "posting CMD_SAVE" );
|
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_SAVE );
|
|
||||||
}
|
|
||||||
m_jniThread.waitToStop();
|
|
||||||
m_jniThread = null;
|
m_jniThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ public class JNIThread extends Thread {
|
||||||
private GameStateInfo m_gsi = new GameStateInfo();
|
private GameStateInfo m_gsi = new GameStateInfo();
|
||||||
|
|
||||||
private boolean m_stopped = false;
|
private boolean m_stopped = false;
|
||||||
|
private boolean m_saveOnStop = false;
|
||||||
private int m_jniGamePtr;
|
private int m_jniGamePtr;
|
||||||
private GameUtils.GameLock m_lock;
|
private GameUtils.GameLock m_lock;
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
|
@ -143,8 +144,12 @@ public class JNIThread extends Thread {
|
||||||
m_queue = new LinkedBlockingQueue<QueueElem>();
|
m_queue = new LinkedBlockingQueue<QueueElem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void waitToStop() {
|
public void waitToStop( boolean save )
|
||||||
|
{
|
||||||
|
synchronized ( this ) {
|
||||||
m_stopped = true;
|
m_stopped = true;
|
||||||
|
m_saveOnStop = save;
|
||||||
|
}
|
||||||
handle( JNICmd.CMD_NONE ); // tickle it
|
handle( JNICmd.CMD_NONE ); // tickle it
|
||||||
try {
|
try {
|
||||||
// Can't pass timeout to join. There's no way to kill
|
// Can't pass timeout to join. There's no way to kill
|
||||||
|
@ -251,10 +256,31 @@ public class JNIThread extends Thread {
|
||||||
Message.obtain( m_handler, TOOLBAR_STATES ).sendToTarget();
|
Message.obtain( m_handler, TOOLBAR_STATES ).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void save_jni()
|
||||||
|
{
|
||||||
|
// If server has any work to do, e.g. clean up after showing a
|
||||||
|
// remote- or robot-moved dialog, let it do so before saving
|
||||||
|
// state. In some cases it'll otherwise drop the move.
|
||||||
|
XwJNI.server_do( m_jniGamePtr );
|
||||||
|
|
||||||
|
XwJNI.game_getGi( m_jniGamePtr, m_gi );
|
||||||
|
GameSummary summary = new GameSummary( m_gi );
|
||||||
|
XwJNI.game_summarize( m_jniGamePtr, summary );
|
||||||
|
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
|
||||||
|
GameUtils.saveGame( m_context, state, m_lock, false );
|
||||||
|
DBUtils.saveSummary( m_context, m_lock, summary );
|
||||||
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
boolean[] barr = new boolean[2]; // scratch boolean
|
boolean[] barr = new boolean[2]; // scratch boolean
|
||||||
while ( !m_stopped ) {
|
for ( ; ; ) {
|
||||||
|
synchronized ( this ) {
|
||||||
|
if ( m_stopped ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QueueElem elem;
|
QueueElem elem;
|
||||||
Object[] args;
|
Object[] args;
|
||||||
try {
|
try {
|
||||||
|
@ -271,18 +297,7 @@ public class JNIThread extends Thread {
|
||||||
if ( nextSame( JNICmd.CMD_SAVE ) ) {
|
if ( nextSame( JNICmd.CMD_SAVE ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// If server has any work to do, e.g. clean up after
|
save_jni();
|
||||||
// showing a remote- or robot-moved dialog, let it do
|
|
||||||
// so before saving state. In some cases it'll
|
|
||||||
// otherwise drop the move.
|
|
||||||
XwJNI.server_do( m_jniGamePtr );
|
|
||||||
|
|
||||||
XwJNI.game_getGi( m_jniGamePtr, m_gi );
|
|
||||||
GameSummary summary = new GameSummary( m_gi );
|
|
||||||
XwJNI.game_summarize( m_jniGamePtr, summary );
|
|
||||||
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
|
|
||||||
GameUtils.saveGame( m_context, state, m_lock, false );
|
|
||||||
DBUtils.saveSummary( m_context, m_lock, summary );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_DRAW:
|
case CMD_DRAW:
|
||||||
|
@ -531,6 +546,10 @@ public class JNIThread extends Thread {
|
||||||
|
|
||||||
checkButtons();
|
checkButtons();
|
||||||
}
|
}
|
||||||
|
} // for
|
||||||
|
|
||||||
|
if ( m_saveOnStop ) {
|
||||||
|
save_jni();
|
||||||
}
|
}
|
||||||
} // run
|
} // run
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue