processing-android icon indicating copy to clipboard operation
processing-android copied to clipboard

java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed

Open ranaaditya opened this issue 5 years ago • 4 comments

Screenshot from 2020-07-11 11-13-46

@codeanticode I was testing the features of Pgraphics API, and found this issue with noClip()

Region.Op.REPLACE has been depreceated from Android-API 26 onwards as mentioned in Android-docs here

Now only possible options are INTERSECT and DIFFERENCE . found this on stackoverflow

please guide how to solve this issue !

ranaaditya avatar Jul 11 '20 06:07 ranaaditya

I don't know if there's any way around this, it seems the Android change just makes it pretty much impossible for Processing to implement the noClip() function as-is at API level 26.

I've been using the following two functions as a compromise - popClip() restores the state before the corresponding pushClip() (which includes resetting more than just the clipping state..):

void pushClip(float x, float y, float x2, float y2) {
  if (g instanceof PGraphicsAndroid2D) ((PGraphicsAndroid2D)g).canvas.save();
  g.clip(x, y, x2, y2);
}
void popClip() {
  if (g instanceof PGraphicsAndroid2D) ((PGraphicsAndroid2D)g).canvas.restore();
  else g.noClip();
}

dzaima avatar Jul 11 '20 11:07 dzaima

I don't know if there's any way around this, it seems the Android change just makes it pretty much impossible for Processing to implement the noClip() function as-is at API level 26.

I've been using the following two functions as a compromise - popClip() restores the state before the corresponding pushClip() (which includes resetting more than just the clipping state..):

void pushClip(float x, float y, float x2, float y2) {
  if (g instanceof PGraphicsAndroid2D) ((PGraphicsAndroid2D)g).canvas.save();
  g.clip(x, y, x2, y2);
}
void popClip() {
  if (g instanceof PGraphicsAndroid2D) ((PGraphicsAndroid2D)g).canvas.restore();
  else g.noClip();
}

Hi @dzaima its quite possible to make everything work again without doing much effort, android has deprecated the use of Region.Op.REPLACE but has other enum variables for the same depends upon the function we want to use.

ranaaditya avatar Jul 11 '20 16:07 ranaaditya

Hi @dzaima its quite possible to make everything work again without doing much effort, android has deprecated the use of Region.Op.REPLACE but has other enum variables for the same depends upon the function we want to use.

The other enum values - INTERSECT and DIFFERENCE - only allow for reducing the size of the clip, whereas noClip() needs to expand it. The removal of Region.Op.REPLACE is specifically because it allowed extending the size of the clip. No other method, other than than restore(), as far as I can tell, can be used to increase the clip size. See the deprecation message here.

dzaima avatar Jul 11 '20 17:07 dzaima

Hi @dzaima its quite possible to make everything work again without doing much effort, android has deprecated the use of Region.Op.REPLACE but has other enum variables for the same depends upon the function we want to use.

The other enum values - INTERSECT and DIFFERENCE - only allow for reducing the size of the clip, whereas noClip() needs to expand it. The removal of Region.Op.REPLACE is specifically because it allowed extending the size of the clip. No other method, other than than restore(), as far as I can tell, can be used to increase the clip size. See the deprecation message here.

Agreed with your discussion

Any way to change the android-mode API to still have this option for Android API > 26

ranaaditya avatar Jul 11 '20 18:07 ranaaditya