-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
C# Wrapper System.AccessViolationException #1280
Comments
@Cavan09 I have no idea what could be causing this. And I do not have experience with C#. Have you become any wiser in the meantime? |
I think that the problem is that the Garbage Collector moves the buffers "after running multiple translations". fixed (byte* pInBuf = converted, pOutBuff = outBuff) // Prevents GarbageCollector from moving the buffers |
I tried reproducing this and suspect it has something to do with longer strings and perhaps exceeding the All is well for these:
But once we exceed an input buffer size of 2048, garbage starts to appear at the end:
... somewhat later ...
The last quasi-successful try (it doesn't crash, but the returned translation is garbage at the end):
And then it throws an exception on this one:
Your "fix" did not help me. Nor did trying to avoid the memory manager by allocating buffers directly from the marhsaler ( Do you know the size of your inputs? Are they relatively small or might something similar be happening there? |
Without having looket much further into it, I think that you are right: This problem has to do with the string length. |
I was wondering if there are any C# devs here that may have experience using LibLouis and using the DLLImport to run translations. I've put together a basic sample of what I'm doing (leaving out some logging and a some integration code).
Generally the code is working just fine, however after running multiple translations in a longer process I tend to get smacked with a couple exceptions which cannot be caught by through try catch. These exceptions are:
System.AccessViolationException - Read/Writing protected memory.
I have tried this on several difference machines, as well as VM's. All yield the same results, and I call the lou_free() method after any process has finished. For testing, I have also tried calling it after each translation (I know that is not correct, I was just hoping it might clear any potential memory issues).
The versions I have tested are:
liblouis 3.24.0
liblouis 3.22.0
If there is any additional info needed please let me know.
The code below is the wrapper.
The text was updated successfully, but these errors were encountered: