Multiple instances of OCR causes Java crash

Asked by Dan

I am trying to run two processes at the same time with two browsers using Selenium and Sikuli. When Sikuli does an OCR of an image on both threads at the same time, it causes Java to crash. When I put a semaphore there so it will only do one at a time, it works fine. But this will be much slower when many browsers are running. Here is the code:

byte[] thisScreen = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
BufferedImage screenImage = ImageIO.read(new ByteArrayInputStream(thisScreen));
Image thisImage = new Image(screenImage);
String pageText = thisImage.text();

It causes this Java error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000068b587c3, pid=4144, tid=7252
#
# JRE version: Java(TM) SE Runtime Environment (8.0_45-b14) (build 1.8.0_45-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [libtesseract-3.dll+0x1587c3]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Project\TicketPullSel\hs_err_pid4144.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Dan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

currently nearly nothing in SikuliX is tread-safe.

So you have to find an appropriate solution, to coordinate the usage of the TextRecognizer instance, that is used with Image.text().

what about delegating the text read to a service class, where you could use synchronized to take care that the read is done one after the other?

Revision history for this message
Dan (mendels99) said :
#2

I did not realize it was not thread safe. I have a workaround.