From ca2dc0b78f8c2306f1fe048f8a5b5d286ee6f441 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 19 Aug 2020 13:48:30 -0700 Subject: [PATCH] start GamePtr with refcount of 1 (for consistency) --- .../src/main/java/org/eehouse/android/xw4/jni/XwJNI.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index 56532a872..00a95a2bf 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -39,7 +39,7 @@ public class XwJNI { public static class GamePtr implements AutoCloseable { private long m_ptrGame = 0; - private int m_refCount = 0; + private int m_refCount = 1; private long m_rowid; private String mStack; @@ -59,6 +59,7 @@ public class XwJNI { public synchronized GamePtr retain() { + Assert.assertTrueNR( 0 < m_refCount ); ++m_refCount; Log.d( TAG, "retain(this=%H, rowid=%d): refCount now %d", this, m_rowid, m_refCount ); @@ -230,7 +231,7 @@ public class XwJNI { CommonPrefs cp, TransportProcs procs ) { - GamePtr gamePtr = initGameJNI( rowid ).retain(); + GamePtr gamePtr = initGameJNI( rowid ); if ( ! game_makeFromStream( gamePtr, stream, gi, dictNames, dictBytes, dictPaths, langName, util, draw, cp, procs ) ) { @@ -249,7 +250,7 @@ public class XwJNI { GamePtr gamePtr = initGameJNI( 0 ); game_makeNewGame( gamePtr, gi, dictNames, dictBytes, dictPaths, langName, util, draw, cp, procs ); - return gamePtr.retain(); + return gamePtr; } // hack to allow cleanup of env owned by thread that doesn't open game