Skip to content

Proper way to change matrix from TransformFilter #28

Open
@puelocesar

Description

@puelocesar

So, I'm testing a very basic setup:

             Image1 \
                     \
                       - >  blend -> view
                     /
Image2 -> transform /

Problem is, I want to modify the transform matrix based on user input. As I couldn't find any way to modify TransformFilter matrix after it's created, I'm destroying it and recreating it with the new matrix.

It's working fine on emulator, but when running on device, it always crash after a few edits. Sometimes it crashes due OutOfMemory error, and sometimes it crashes with:

08-26 15:56:13.173    4312-4327/? E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 270
    java.lang.ArrayIndexOutOfBoundsException: length=1; index=-2
            at project.android.imageprocessing.filter.MultiInputFilter.newTextureReady(MultiInputFilter.java:87)
            at project.android.imageprocessing.input.GLTextureOutputRenderer.drawFrame(GLTextureOutputRenderer.java:88)
            at project.android.imageprocessing.input.ImageResourceInput.drawFrame(ImageResourceInput.java:67)
            at project.android.imageprocessing.GLRenderer.onDrawFrame(GLRenderer.java:232)
            at project.android.imageprocessing.FastImageProcessingPipeline.onDrawFrame(FastImageProcessingPipeline.java:91)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)

And here are the methods I'm calling to remove the transform, and then reinstall it:

private void clean() {
        pipeline.pauseRendering();

        input2.removeTarget(transform);
        blend.clearRegisteredFilterLocations();

        pipeline.addFilterToDestroy(transform);

        transform.removeTarget(blend);
        transform.destroy();
    }

    private void reinstallFilters() {

        Matrix.translateM(matrix, 0, matrix, 0, translatex, translatey, 0);

        transform = new TransformFilter(matrix, false, false);

//        debugMatrix();

        input2.addTarget(transform);
        transform.addTarget(blend);

        blend.registerFilterLocation(input);
        blend.registerFilterLocation(transform);

        pipeline.startRendering();
        preview.requestRender();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions