nguyenq / tess4j

Java JNA wrapper for Tesseract OCR API
Apache License 2.0
1.58k stars 372 forks source link

TessBaseAPIInit1 calls fail with "Invalid memory access" on Windows 10 with included Tesseract Windows 32-bit DLL #258

Closed cdokolas closed 3 months ago

cdokolas commented 7 months ago

The problem only exists on Windows 10 (not Windows 11!) when using a 32-bit JRE (even with fully-updated VC runtimes). All operations fail because the necessary TessBaseAPIInit1 call fails with an "Invalid memory access" exception like this:

java.lang.Error: Invalid memory access
        at net.sourceforge.tess4j.TessAPI1.TessBaseAPIInit1(Native Method)
        at net.sourceforge.tess4j.Tesseract1.init(Tesseract1.java:427)
        at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:630)
        at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:613)
        at org.example.Main.test1(Main.java:130)
        at org.example.Main.main(Main.java:54)

...or this:

java.lang.Error: Invalid memory access
        at com.sun.jna.Native.invokeInt(Native Method)
        at com.sun.jna.Function.invoke(Function.java:426)
        at com.sun.jna.Function.invoke(Function.java:361)
        at com.sun.jna.Library$Handler.invoke(Library.java:270)
        at jdk.proxy1/jdk.proxy1.$Proxy0.TessBaseAPIInit1(Unknown Source)
        at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:447)
        at net.sourceforge.tess4j.Tesseract.createDocuments(Tesseract.java:650)
        at net.sourceforge.tess4j.Tesseract.createDocuments(Tesseract.java:633)
        at org.example.Main.test2(Main.java:148)
        at org.example.Main.main(Main.java:55)

The problem is clearly with the build of the 32-bit DLL because we've managed (with some difficulty) to build one that worked fine. It was tested by substituting the one inside the official tess4j-5.8.0.jar.

The issue was verified...

With the following Tess4J versions:

On the following 32-bit JREs:

nguyenq commented 7 months ago

@cdokolas The library was tested with both Java 8 (1.8.0_401) 32- and 64-bit on Windows 11. The Windows binaries were built using VS2022 with the following settings:

Windows SDK version: 10.0.22000.0 Platform Toolset: Visual Studio 2022 (v143) C++ Language Standard: ISO C++20 Standard (/std:c++20) C Language Standard: Default (Legacy MSVC)

nguyenq commented 7 months ago

Possible duplicate of Issue #250.

nguyenq commented 6 months ago

@cdokolas Can you test with the latest version in the repo?

cdokolas commented 6 months ago

@cdokolas Can you test with the latest version in the repo?

Unfortunately not at the moment. I don't have a Windows 10 system in hand :(

nguyenq commented 6 months ago

I had the tess4j version in question run successfully on Windows 10 Version 22H2.

The latest Windows binaries are built with:

Windows SDK version: 10.0.22621.0 Platform Toolset: Visual Studio 2022 (v143) C++ Language Standard: ISO C++17 Standard (/std:c++17) C Language Standard: ISO C17 (2018) Standard (/std:c17)

nguyenq commented 3 months ago

Close the ticket. Unable to reproduce the issue on Windows 10.