Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error when drawing a path #47

Closed
ghost opened this issue Oct 25, 2013 · 2 comments
Closed

Fatal error when drawing a path #47

ghost opened this issue Oct 25, 2013 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 25, 2013

From LogCat:

E/AndroidRuntime(26958): FATAL EXCEPTION: main
E/AndroidRuntime(26958): java.lang.UnsupportedOperationException
    at android.view.GLES20Canvas.quickReject(GLES20Canvas.java:490)
    at com.qozix.tileview.paths.PathManager.onDraw(PathManager.java:115)

Running on Android 4.0.4

Most likely relates to this: http://stackoverflow.com/questions/10173968/unsupportedoperationexception-in-gles20canvas-clippath-with-hardware-acceleratio so should be an easy fix.

@ghost
Copy link
Author

ghost commented Oct 25, 2013

Proposed fix:

@SuppressLint("NewApi")
@Override
public void onDraw( Canvas canvas ) {
    if ( shouldDraw ) {
        float scale = (float) detailManager.getScale();
        matrix.setScale( scale, scale );
        for ( DrawablePath drawablePath : paths ) {
            drawingPath.set( drawablePath.path );
            drawingPath.transform( matrix );
            if (android.os.Build.VERSION.SDK_INT >= 11 && canvas.isHardwareAccelerated()
            && android.os.Build.VERSION.SDK_INT < 16) {
                canvas.drawPath( drawingPath, drawablePath.paint );
            } else if ( !canvas.quickReject( drawingPath, Canvas.EdgeType.BW ) ) {
                canvas.drawPath( drawingPath, drawablePath.paint );
            }
        }
    }
    super.onDraw( canvas );
}

canvas.quickReject is available for hw accelerated canvas only starting from SDK 4.1 (16) thus calling this on earlier android builds will cause the fatal exception. Furthermore canvas.isHardwareAccelerated() check is available only since SDK 11 thus we need to apply multiple conditions here. I believe that pre SDK 11 builds have HW acceleration turned off by default so this shouldn't be causing any issues on older builds.

@moagrius
Copy link
Owner

included in your PR. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant