rmtheis / tess-two

Fork of Tesseract Tools for Android
Apache License 2.0
3.76k stars 1.38k forks source link

Fix https://github.com/rmtheis/tess-two/issues/159 #267

Closed alexcohn closed 5 years ago

alexcohn commented 5 years ago

As a result of discussion with @DanBloomberg, the test that was commented out, can now be re-enabled. The change for Pixa.replacePix() method only concerns the JavaDoc, but is very important. I would suggest to rewrite the test such:

public void testPixaReplacePix() {
    Pixa pixa = Pixa.createPixa(0, 640, 480);

    // Populate the Pixa.
    addBlockToPixa(pixa, 0, 0, 640, 480, 8);

    // Replace the existing Pix.
    pixa.replacePix(0, new Pix(320, 240, 8), new Box(320, 240, 320, 240));

    // Ensure the replacement was successful.
    Pix returnedPix = pixa.getPix(0);
    Box returnedBox = pixa.getBox(0);

    assertEquals(320, returnedPix.getWidth());
    assertEquals(240, returnedPix.getHeight());
    assertEquals(8, returnedPix.getDepth());

    assertEquals(320, returnedBox.getX());
    assertEquals(240, returnedBox.getY());
    assertEquals(320, returnedBox.getWidth());
    assertEquals(240, returnedBox.getHeight());

    returnedPix.recycle();
    returnedBox.recycle();
    pixa.recycle();
}

This should emphasize that the parameters of replacePix method actually become zombies, and should not be recycled or referenced anymore.

rmtheis commented 5 years ago

Nice. Thanks for tracking down the root of the issue here.