adaptech-cz / Tesseract4Android

Fork of tess-two rewritten from scratch to support latest version of Tesseract OCR.
Apache License 2.0
721 stars 111 forks source link

Crash on initialization on some devices #55

Closed DaiZrei closed 11 months ago

DaiZrei commented 1 year ago

Hello. I use the compiled version of the library in my application. When I run the app on my Google Pixel 6a everything works great. But if I run the application on a weaker device or on a device with an old version of Android, I get a crash with the following error: A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 12321. Tested on two devices: Xiaomi Redmi note 10 Pro(Android 11) and Xiaomi Mi 5(Android 8). All attempts to correct the error, to no avail. image

Detail log:

22971-22971 libc com.example.forblitz.livestatistics A Fatal signal 6 (SIGABRT), code -6 in tid 22971 (.livestatistics) 2023-06-09 02:16:51.102 23086-23086 DEBUG pid-23086 A pid: 22971, tid: 22971, name: .livestatistics >>> com.example.forblitz.livestatistics <<< 2023-06-09 02:16:51.119 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/2 pc 000000000021cfc4 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (_ZNK9tesseract7ERRCODE5errorEPKcNS_16TessErrorLogCodeES2_z+368) 2023-06-09 02:16:51.119 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/3 pc 0000000000232cd8 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (_ZN9tesseract8Classify22InitAdaptiveClassifierEPNS_15TessdataManagerE+420) 2023-06-09 02:16:51.119 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/4 pc 0000000000310b08 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (ZN9tesseract7Wordrec14program_editupERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEPNS_15TessdataManagerESB+84) 2023-06-09 02:16:51.120 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/5 pc 00000000001d1c90 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (_ZN9tesseract9Tesseract14init_tesseractERKNSt6ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_S9_NS_13OcrEngineModeEPPciPKNS1_6vectorIS7_NS5_IS7_EEEESH_bPNS_15TessdataManagerE+688) 2023-06-09 02:16:51.120 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/6 pc 0000000000180d78 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (_ZN9tesseract11TessBaseAPI4InitEPKciS2_NS_13OcrEngineModeEPPciPKNSt6ndk16vectorINS6_12basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEENSB_ISD_EEEESH_bPFbS2_PNS7_IcSC_EEE+1040) 2023-06-09 02:16:51.120 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/7 pc 0000000000180958 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (_ZN9tesseract11TessBaseAPI4InitEPKcS2_NS_13OcrEngineModeEPPciPKNSt6__ndk16vectorINS6_12basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEENSB_ISD_EEEESH_b+56) 2023-06-09 02:16:51.120 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/8 pc 00000000003134f0 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/lib/arm64/libtesseract.so (Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInitOem+136) 2023-06-09 02:16:51.121 23086-23086 DEBUG pid-23086 A https://github.com/adaptech-cz/Tesseract4Android/issues/9 pc 0000000000043f34 /data/app/com.example.forblitz.livestatistics-SH0kovyRsnozQwxSJhbXWg==/oat/arm64/base.odex (offset 0x30000)

Robyer commented 1 year ago

Hi, does it crash with the sample app too?

If it does, could you quickly try few older Tesseract4Android versions if it crashes there too?

And finally, to see where it really crashes, you should compile the library manually in debug mode. To do it with sample project:

  1. Comment out this line - https://github.com/adaptech-cz/Tesseract4Android/blob/6ee37bceb49dba68395642b7d9dfa2c82cfcd4ac/sample/build.gradle#L50
  2. Uncomment this line - https://github.com/adaptech-cz/Tesseract4Android/blob/6ee37bceb49dba68395642b7d9dfa2c82cfcd4ac/sample/build.gradle#L60
  3. Uncomment these lines (and you can also change it to 'standard' instead of the 'openmp' variant) - https://github.com/adaptech-cz/Tesseract4Android/blob/6ee37bceb49dba68395642b7d9dfa2c82cfcd4ac/sample/build.gradle#L38-L44
  4. Then comment out this line in tesseract4android library - https://github.com/adaptech-cz/Tesseract4Android/blob/6ee37bceb49dba68395642b7d9dfa2c82cfcd4ac/tesseract4android/build.gradle#L47
  5. Now in Android Studio where you have opened the sample project, make sure your build type is set to debug, then open the Run/Debug configuration window and on the tab Debugger make sure that Debug type is set to Dual (Java + Native). Then just run the app in debugger and hopefully you will be able to see where or why it crashes.
DaiZrei commented 1 year ago

I tried compiling your Sample, no problem with it. But I tried moving it to a new project and unfortunately I get the same problem. I also tried to compile the native version of the library and got the following errors in the debugger image

Robyer commented 1 year ago

@DaiZrei What *.traineddata file are you using? If you try the eng.traineddata from the sample, does it work in your project?

If it doesn't, maybe you have some problem with the path where that traineddata file is saved? Because if sample project works for you, then there must be something wrong in your code.

DaiZrei commented 1 year ago

@DaiZrei What *.traineddata file are you using? If you try the eng.traineddata from the sample, does it work in your project?

If it doesn't, maybe you have some problem with the path where that traineddata file is saved? Because if sample project works for you, then there must be something wrong in your code.

I have completely transferred all the classes of the Sample project from your repository to the new project, including the traineddata file. And there are problems in the new project. And if I use it in your project, then everything is fine. Perhaps there are some nuances of the project configuration?

Robyer commented 1 year ago

@DaiZrei Can you create some reproducible project which will fail this way on any device/emulator? Or does the issue still happens only on these specific devices?

Robyer commented 1 year ago

@DaiZrei Random idea - what happens when you specify ndkVersion in your new project to the same value as used here?

https://github.com/adaptech-cz/Tesseract4Android/blob/0364a8716b93c44b399374b10eec63d60b55ad3d/tesseract4android/build.gradle#L9

I believe older version is used by default so maybe that is the difference which causes your crashes? EDIT: But since the library is already built, it doesn't make sense actually...

Robyer commented 1 year ago

@DaiZrei Have you solved your problem? I'd like to know what was wrong, or if there is still something wrong with the library.

Robyer commented 11 months ago

I'm closing this due to inactivity. If you still have the problem, feel free to reopen this.