Skip to content

Commit 0a358f3

Browse files
committed
ANDROID: fix issue with crash on minimise with googleos
1 parent d5fe343 commit 0a358f3

File tree

6 files changed

+38
-17
lines changed

6 files changed

+38
-17
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2019-08-19 (0.12.15)
2+
ANDROID: fix issue with crash on minimise with googleos
3+
ANDROID: update to androidx
4+
15
2019-07-27 (0.12.15)
26
SDL: added -n command line option to run then not pause for back key
37

src/platform/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
// app can use the API features included in this API level and lower.
5-
compileSdkVersion 27
5+
compileSdkVersion 28
66

77
// can override some attributes in main/AndroidManifest.xml
88
defaultConfig {
@@ -47,6 +47,6 @@ android {
4747
}
4848

4949
dependencies {
50-
implementation 'com.android.support:support-compat:27.1.1'
50+
implementation 'androidx.core:core:1.0.0'
5151
testImplementation 'junit:junit:4.12'
5252
}

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import android.os.Bundle;
2525
import android.os.Environment;
2626
import android.os.Handler;
27-
import android.support.annotation.NonNull;
28-
import android.support.v4.app.ActivityCompat;
29-
import android.support.v4.content.ContextCompat;
27+
import androidx.annotation.NonNull;
28+
import androidx.core.app.ActivityCompat;
29+
import androidx.core.content.ContextCompat;
3030
import android.util.Base64;
3131
import android.util.DisplayMetrics;
3232
import android.util.Log;

src/platform/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.3.2'
9-
classpath "com.github.ben-manes:gradle-versions-plugin:0.20.0"
8+
classpath 'com.android.tools.build:gradle:3.4.2'
9+
classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0"
1010
}
1111
}
1212

src/platform/android/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
12+
android.enableJetifier=true
13+
android.useAndroidX=true
1214
org.gradle.jvmargs=-Xmx1536m
1315

1416
# When configured, Gradle will run in incubating parallel mode.

src/platform/android/jni/display.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool Graphics::construct(int fontId) {
143143
if (_screen && _screen->create(_w, _h)) {
144144
_drawTarget = _screen;
145145
maSetColor(DEFAULT_BACKGROUND);
146-
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, WINDOW_FORMAT_RGBA_8888);
146+
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM);
147147
result = true;
148148
} else {
149149
trace("Failed to create canvas");
@@ -157,18 +157,33 @@ bool Graphics::construct(int fontId) {
157157
void Graphics::redraw() {
158158
if (_app->window != NULL && !_paused) {
159159
ANativeWindow_Buffer buffer;
160-
if (ANativeWindow_lock(_app->window, &buffer, NULL) < 0) {
160+
bool locked = ANativeWindow_lock(_app->window, &buffer, NULL) == 0;
161+
if (!locked) {
161162
trace("Unable to lock window buffer");
162163
} else {
163-
void *pixels = buffer.bits;
164-
int width = MIN(_w, MIN(buffer.width, _screen->_w));
165-
int height = MIN(_h, MIN(buffer.height, _screen->_h));
166-
for (int y = 0; y < height; y++) {
167-
pixel_t *line = _screen->getLine(y);
168-
memcpy((pixel_t *)pixels, line, width * sizeof(pixel_t));
169-
pixels = (pixel_t*)pixels + buffer.stride;
164+
if (buffer.format != AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) {
165+
ANativeWindow_unlockAndPost(_app->window);
166+
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM);
167+
locked = ANativeWindow_lock(_app->window, &buffer, NULL) == 0;
168+
trace("Restore format %d", locked);
169+
}
170+
if (buffer.format != AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) {
171+
ANativeWindow_unlockAndPost(_app->window);
172+
ANativeWindow_setBuffersGeometry(_app->window, 0, 0, AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM);
173+
locked = false;
174+
trace("Restore format failed");
175+
}
176+
if (locked) {
177+
void *pixels = buffer.bits;
178+
int width = MIN(_w, MIN(buffer.width, _screen->_w));
179+
int height = MIN(_h, MIN(buffer.height, _screen->_h));
180+
for (int y = 0; y < height; y++) {
181+
pixel_t *line = _screen->getLine(y);
182+
memcpy((pixel_t *)pixels, line, width * sizeof(pixel_t));
183+
pixels = (pixel_t*)pixels + buffer.stride;
184+
}
185+
ANativeWindow_unlockAndPost(_app->window);
170186
}
171-
ANativeWindow_unlockAndPost(_app->window);
172187
}
173188
}
174189
}

0 commit comments

Comments
 (0)