@@ -603,11 +603,13 @@ private void drawInLayer(Layer layer, Drawable drawable, Paint_Delegate paint,
603603 createCustomGraphics (originalGraphics , paint , compositeOnly , forceSrcMode ) :
604604 (Graphics2D ) originalGraphics .create ();
605605
606- try {
607- drawable .draw (configuredGraphics2D , paint );
608- } finally {
609- // dispose Graphics2D object
610- configuredGraphics2D .dispose ();
606+ if (configuredGraphics2D != null ) {
607+ try {
608+ drawable .draw (configuredGraphics2D , paint );
609+ } finally {
610+ // dispose Graphics2D object
611+ configuredGraphics2D .dispose ();
612+ }
611613 }
612614 }
613615
@@ -680,11 +682,13 @@ private void restoreLayer(Layer dstLayer) {
680682 Graphics2D g = createCustomGraphics (baseGfx , mLocalLayerPaint ,
681683 true /*alphaOnly*/ , false /*forceSrcMode*/ );
682684
683- g .drawImage (mLocalLayer .getImage (),
684- mLayerBounds .left , mLayerBounds .top , mLayerBounds .right , mLayerBounds .bottom ,
685- mLayerBounds .left , mLayerBounds .top , mLayerBounds .right , mLayerBounds .bottom ,
686- null );
687- g .dispose ();
685+ if (g != null ) {
686+ g .drawImage (mLocalLayer .getImage (),
687+ mLayerBounds .left , mLayerBounds .top , mLayerBounds .right , mLayerBounds .bottom ,
688+ mLayerBounds .left , mLayerBounds .top , mLayerBounds .right , mLayerBounds .bottom ,
689+ null );
690+ g .dispose ();
691+ }
688692
689693 baseGfx .dispose ();
690694 }
@@ -714,11 +718,17 @@ private Graphics2D createCustomGraphics(Graphics2D original, Paint_Delegate pain
714718 Shader_Delegate shaderDelegate = paint .getShader ();
715719 if (shaderDelegate != null ) {
716720 if (shaderDelegate .isSupported ()) {
717- java .awt .Paint shaderPaint = shaderDelegate .getJavaPaint ();
718- assert shaderPaint != null ;
719- if (shaderPaint != null ) {
720- g .setPaint (shaderPaint );
721- customShader = true ;
721+ // shader could have a local matrix that's not valid (for instance 0 scaling).
722+ if (shaderDelegate .isValid ()) {
723+ java .awt .Paint shaderPaint = shaderDelegate .getJavaPaint ();
724+ assert shaderPaint != null ;
725+ if (shaderPaint != null ) {
726+ g .setPaint (shaderPaint );
727+ customShader = true ;
728+ }
729+ } else {
730+ g .dispose ();
731+ return null ;
722732 }
723733 } else {
724734 Bridge .getLog ().fidelityWarning (LayoutLog .TAG_SHADER ,
@@ -742,7 +752,7 @@ private Graphics2D createCustomGraphics(Graphics2D original, Paint_Delegate pain
742752
743753 if (forceSrcMode ) {
744754 g .setComposite (AlphaComposite .getInstance (
745- AlphaComposite .SRC , ( float ) alpha / 255.f ));
755+ AlphaComposite .SRC , alpha / 255.f ));
746756 } else {
747757 boolean customXfermode = false ;
748758 Xfermode_Delegate xfermodeDelegate = paint .getXfermode ();
@@ -766,7 +776,7 @@ private Graphics2D createCustomGraphics(Graphics2D original, Paint_Delegate pain
766776 // that will handle the alpha.
767777 if (customXfermode == false && alpha != 0xFF ) {
768778 g .setComposite (AlphaComposite .getInstance (
769- AlphaComposite .SRC_OVER , ( float ) alpha / 255.f ));
779+ AlphaComposite .SRC_OVER , alpha / 255.f ));
770780 }
771781 }
772782
0 commit comments