commit 2bd3d0fb941cdcfd3761bd7611a9320faadf67f3
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Oct 16 16:35:46 2020 +0100

    Detect if the texture we are trying to upload is too large and return an error.

diff --git a/src/main/java/org/distorted/library/main/DistortedLibrary.java b/src/main/java/org/distorted/library/main/DistortedLibrary.java
index 199d6c5..d7b1dc8 100644
--- a/src/main/java/org/distorted/library/main/DistortedLibrary.java
+++ b/src/main/java/org/distorted/library/main/DistortedLibrary.java
@@ -221,6 +221,7 @@ public class DistortedLibrary
 
   private static ExceptionListener mListener;
   private static Resources mResources;
+  private static int mMaxTextureSize;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // private: hide this from Javadoc
@@ -994,6 +995,10 @@ public class DistortedLibrary
       mGLSL = (major==3 && minor==0) ? 300 : 310;
       }
 
+    int[] maxTextureSize = new int[1];
+    GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
+    mMaxTextureSize = maxTextureSize[0];
+
     android.util.Log.e("DISTORTED", "Using OpenGL ES "+major+"."+minor);
     mGLSL_VERSION = "#version "+mGLSL+" es\n";
 
@@ -1086,6 +1091,15 @@ public class DistortedLibrary
     mBlitProgram       = null;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Return the maximum size of the texture supported by the driver.
+ */
+  public static int getMaxTextureSize()
+    {
+    return mMaxTextureSize;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Returns the maximum number of effects of a given type that can be simultaneously applied to a
diff --git a/src/main/java/org/distorted/library/main/DistortedTexture.java b/src/main/java/org/distorted/library/main/DistortedTexture.java
index 32de684..20ac73f 100644
--- a/src/main/java/org/distorted/library/main/DistortedTexture.java
+++ b/src/main/java/org/distorted/library/main/DistortedTexture.java
@@ -135,11 +135,25 @@ public class DistortedTexture extends InternalSurface
  * to GLSurfaceView.onSurfaceCreated) because only after this point can the Library upload it to the GPU!
  *
  * @param bmp The android.graphics.Bitmap object to apply effects to and display.
+ * @return true if successful, false if texture too large.
  */
-  public void setTexture(Bitmap bmp)
+  public boolean setTexture(Bitmap bmp)
     {
-    mBmp= bmp;
-    markForCreation();
+    int width = bmp.getWidth();
+    int height= bmp.getHeight();
+    int max   = DistortedLibrary.getMaxTextureSize();
+
+    if( width>max || height>max )
+      {
+      android.util.Log.e("texture","error, trying to upload too large texture of size "+width+" x "+height+". Max is "+max);
+      return false;
+      }
+    else
+      {
+      mBmp= bmp;
+      markForCreation();
+      return true;
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
