Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error : 'System.AccessViolationException' occurred in InteropRuntimeImplementer.TessApiSignaturesInstance #231

Closed
satishreddy81 opened this issue Dec 21, 2015 · 42 comments
Labels

Comments

@satishreddy81
Copy link

While trying to run Samples with attached image. i am getting following error:

An unhandled exception of type 'System.AccessViolationException' occurred in InteropRuntimeImplementer.TessApiSignaturesInstance

Could please help me? Screen shot attached

untitled

test123

Thanks,
Satish

@charlesw
Copy link
Owner

Opps I forgot to update the Samples to the new Tesseract release (3.0). I'll have a look at doing this tomorrow.

@charlesw
Copy link
Owner

If you've upgraded to 3.0, then it could be due to issue #232. I'll try and put together a fix tomorrow morning.

@YoungjaeKim
Copy link

The AccessViolationException occurs not only x64, but also x86 version in 3.0.0 when I perform AnalyzeLayout(); method in 50% probability. @charlesw did you figure it out also?

@charlesw
Copy link
Owner

Yes, I have noticed that some of the time I'm getting AccessViolationException as well. I'll have a look but for the meantime I'd strongly suggest using version 2.4.1 instead.

@YoungjaeKim
Copy link

Always appreciate your effort. thanks.

@charlesw
Copy link
Owner

Just rebuilt the native tesseract libraries and re-added them (ab4d506). Seems to be working for me now however would appreciate it if someone else could also verify that it's working for them too.

@charlesw
Copy link
Owner

Note to use the samples in dev you'll need to build local copy of the Tesseract nuget package (3.0.1) and place it in your nuget package path:

  1. Execute build.bat to build the nuget package and copy it to `C:\Nuget packages`` (or wherever you want to store your local nuget packages
  2. From VS 2015 (note its a similar process in older versions):
    1. Click Tools -> Options
    2. Select Nuget Package Manager -> Package Sources
    3. Click the Add button to add a new source and C:\Nuget packages for the source and a meaningful name and click Update
  3. VS should now be able to find your copy of the Tesseract nuget package

Note: You can skip step 2 if you've already got this setup of course.

@ermGit
Copy link

ermGit commented Dec 24, 2015

Did this ever get solved? I am using 3.0.1 from NuGet package install. I am receiving the same error: System.AccessViolationException' occurred in InteropRuntimeImplementer.TessApiSignaturesInstance
when GetText() is called.

What version should I use if I build my own nuget package?

@charlesw
Copy link
Owner

I'm guessing that the answer is no as you're still getting the error. I think that something is wrong with the native build of the tesseract library. Not sure what though.

@Rodbourn
Copy link

Rodbourn commented Jan 5, 2016

I'm having the same problem as well.

@charlesw
Copy link
Owner

charlesw commented Jan 6, 2016

I've split of the samples into the own repo (https://github.com/charlesw/tessseract-samples) to make it easier to maintain and so they can be improved independently of this wrapper.

I've also had a quick further look at this bug and unfortunately I cannot reliably reproduce it (just ran the console sample 20+ times and it didn't occur once). Can anyone else check this out and ideally provide an example more info on how to reproduce this?

@Rodbourn
Copy link

@charlesw, I get the error every time without fail in the same way as @satishreddy81. I started down the path of building all of the dependencies from scratch, but it didn't help. This happens when I run any number of inputs, not just the samples not just on occasion.

I tried version 3.0.0 specifically as I had tried 3.0.1, both fail in the same way.

image

@Rodbourn
Copy link

Note, if I force the x86 platform it's intermittent.

@charlesw
Copy link
Owner

Thanks for the extra info. I did do some more testing to see if I could
find a way to reproduce the issue reliable bit still no luck in my
environment. Does it also occur for you outside of vs?
On 11/01/2016 3:46 am, "Rodbourn" notifications@github.com wrote:

Note, if I force the x86 platform it's intermittent.


Reply to this email directly or view it on GitHub
#231 (comment).

@Rodbourn
Copy link

It does, unfortunately. My work around for the moment is to force the platform to x86 and swallow the error if it happens. With the x86 binaries it's much less common.

@charlesw
Copy link
Owner

Quick update on this issue: Unfortunately I'm not making much headway here and still cannot reliably reproduce the issue. I'll look at doing a new build using VS 2015, thanks to the work by @tofutim, and hope that resolves the crash though I'm not confident it will given I have no idea what's causing this.

I'm off to Europe very shortly so may not be able to do until mid\late next week.

@kenlacoste843
Copy link

Hi, i'm currently having the same issue IF I specify a different language, but if I use "eng", no error occurs. BTW I happen to try "chi_sim" and "chi_tra" and both happens to have an AccessViolationError.

@charlesw
Copy link
Owner

charlesw commented Feb 8, 2016

I've released a new prerelease (Tesseract.3.0.2.0-alpha1) on nuget if people can test it out and respond with if it works or not on there setup that would be great. Note that this release used vs2015 to build the dependencies so you'll need to ensure that the vs2015 runtime is installed. VS2015 or .Net 4.6 is not required.

@kenlacoste843
Copy link

Thanks charles, i'll definitely test this one out. best!

@kenlacoste843
Copy link

Hi Charles, good news for the chi_sim language, i'm now able to convert the document into text. This is a great progress for your 3.0.2.0 alpha1! I'm just not sure how to test the other languages. Hopefully someone from the group may help. Thanks a lot again, wonderful work!

For those who wish to test, please execute to your package manager -

Install-Package Tesseract -Version 3.0.2.0-alpha1

samp5
chi_sim

@benoitadam
Copy link

Hi charlesw,
I had the same error but your prerelease solved the problem.
So the version "Tesseract.3.0.2.0-alpha1" works well on VS2015 with French data.
Thank you very much for the correction.

@charlesw
Copy link
Owner

Great, I'll do another set of test runs and assuming all is good do a
proper release tomorrow evening (German time).

On Thu, Feb 11, 2016 at 4:42 PM, dotadam notifications@github.com wrote:

Hi charlesw,
I had the same error but your prerelease solved the problem.
So the version "Tesseract.3.0.2.0-alpha1" works well on VS2015 with French
data.
Thank you very much for the correction.


Reply to this email directly or view it on GitHub
#231 (comment).

@charlesw
Copy link
Owner

Version 3.0.2 has now been released which should hopefully have resolved this issue :)

@kenlacoste843
Copy link

Very nice, we also hope to see the home page of this project updated as well if you don't mind though this has nothing to do with a bug or any. Thanks again!

@kenlacoste843
Copy link

Hi Charles, i'm very sorry but right now when i'm trying to install the project, i'm having these.
image

@charlesw
Copy link
Owner

Looks like something is wrong with your nuget environment. Have you tried
uninstalling & reinstalling the tesseract package.
On 17 Feb 2016 08:28, "kenneth lacoste" notifications@github.com wrote:

Hi Charles, i'm very sorry but right now when i'm trying to install the
project, i'm having these.
[image: image]
https://cloud.githubusercontent.com/assets/10647176/13102616/133ddf5a-d58b-11e5-85a8-b5c94926e2f0.png


Reply to this email directly or view it on GitHub
#231 (comment).

@kenlacoste843
Copy link

that was actually a clean project..have you tried re-installing / installing the tesseract package? are you having any issues? because if not, then probably its due to my network security..

@kenlacoste843
Copy link

And, its ok now..hehe my apologies. 👍

@Abinash01
Copy link

Hi i have the same issue with 3.2.0-alpha2 when using the GetText() method on x64. By the way i am doing this OCR stuff on parallel programming with .Net task(similar to multi threading). My guess is that it fails when GetText() is called within a multithreaded application like a windows service or any other parallel programming. Could you help me out with this?

@tdhintz
Copy link
Contributor

tdhintz commented Mar 17, 2017

I'm using 3.2.0 alpha x64 GetText() multi-thread without a problem, but you must only have one thread per engine. So, when doing multi-thread create a different engine instance for each.

@tdhintz
Copy link
Contributor

tdhintz commented Mar 17, 2017

Hours after I said it was all working we reproduced the problem.

@tdhintz
Copy link
Contributor

tdhintz commented Mar 17, 2017

Seems to be Page.Recognize(). Another place I see it is here. I don't see ResultRenderer class on the GitHub version of the code. Is this stack wonky or is there a different code set?

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiRecognize(HandleRef handle, HandleRef monitor)
at Tesseract.Page.Recognize()
at Tesseract.ResultRenderer.AddPage(Page page)

@charlesw
Copy link
Owner

charlesw commented Mar 17, 2017 via email

@tdhintz
Copy link
Contributor

tdhintz commented Mar 18, 2017

Destructor should release unmanaged resources when used without dispose. Would you like me to make a pull so you can review?

@charlesw
Copy link
Owner

charlesw commented Mar 18, 2017 via email

@tdhintz
Copy link
Contributor

tdhintz commented Mar 18, 2017

It isn't the access violation cause. I just noticed. It only matters for those not as careful.

@tdhintz
Copy link
Contributor

tdhintz commented Mar 18, 2017

I can't push the change. Was I supposed to fork and then make the change?

@charlesw
Copy link
Owner

charlesw commented Mar 18, 2017 via email

@tdhintz
Copy link
Contributor

tdhintz commented Mar 18, 2017

Page.cs from
protected override void Dispose(bool disposing)
{
if (disposing) {
Interop.TessApi.Native.BaseAPIClear(Engine.Handle);
}
}

to

    protected override void Dispose(bool disposing)
    {
        if (! IsDiposed) {
            Interop.TessApi.Native.BaseAPIClear(Engine.Handle);
        }
    }

@tdhintz
Copy link
Contributor

tdhintz commented Mar 20, 2017

I ran a stress test on a memory limited machine and experienced a similar problem when the machine exhausted memory. I repeated the test with 10,000 pages on 2 threads on a dual core with enough memory and did not experience the symptom.

@divyangashah
Copy link

@charlesw can you please look into below issue:
tesseract-ocr/tesseract#2680

It's same issue but, Tesseract version: 4.0.0.0-beta3

Thanks!

@kostelis
Copy link

kostelis commented Jun 1, 2022

I am still running into the same issue using Tesseract version 4.1.1 from NuGet. Did anyone manage to resolve this? It would be great if it could at least throw an exception because currently, the try-catch block is not able to catch it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests