diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ed28cb2..d9c4838 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,13 +1,13 @@ + android:versionCode="28" + android:versionName="2.4"> @@ -39,7 +38,7 @@ + android:label="Interstitial"> true, perform garbage collection prior + * to loading the file. */ - public boolean LoadMODResource(int modresource) { + public boolean LoadMODResource(int modresource, boolean gc) { byte[] modData = null; int currfilesize = 0; InputStream mModfileInStream; @@ -141,6 +143,18 @@ public boolean LoadMODResource(int modresource) { * Allocate a buffer that can hold the current MOD file data. */ try { + /* + * This is a very critical and often very large memory allocation. + * Force the system to perform garbage collection to free up + * memory for the allocation. + * + * This is not recommended practice, as it can affect system + * performance. This should only be called when the user is not + * interacting with the system. + */ + if (gc) { + System.gc(); + } modData = new byte[currfilesize]; } catch (OutOfMemoryError oome) { // Auto-generated catch block. diff --git a/src/com/peculiargames/andmodplug/PlayerThread.java b/src/com/peculiargames/andmodplug/PlayerThread.java index 9abf716..95549cd 100644 --- a/src/com/peculiargames/andmodplug/PlayerThread.java +++ b/src/com/peculiargames/andmodplug/PlayerThread.java @@ -552,7 +552,14 @@ public void run() { * greater than the minbuffer size the audio system reports in the * contructors... */ - short[] mBuffer = new short[BUFFERSIZE]; + short[] mBuffer; + try { + mBuffer = new short[BUFFERSIZE]; + } catch (OutOfMemoryError oome) { + // Auto-generated catch block. + oome.printStackTrace(); + mBuffer = null; + } if (mStart_paused) { mPlaying = false; @@ -564,7 +571,7 @@ public void run() { /* * Main play loop. */ - if (mMytrack != null) { + if ((mMytrack != null) && (mBuffer != null)) { mMytrack.play(); } else {