I am trying to export the Part data as JIIX data in the Editor's callback for onContentChanged. It usually works, but I sometimes get the following exception. Do you have any idea about what's going wrong and what I could do to fix the issue? I tried adding a call to Editor.waitForIdle() before calling export(), but the call never returns and the app hangs if I do that.
2021-05-11 14:52:31.109 19696-19822/com.myapp E/AndroidRuntime: FATAL EXCEPTION: Thread-2361 Process: com.myapp, PID: 19696 java.lang.IllegalStateException: export operation failed, processing may not be over at com.myscript.iink.NativeFunctions.doExport1(Native Method) at com.myscript.iink.Editor.export_(Editor.java:971) at com.myapp.IinkLayer.processContentChanged(IinkLayer.java:478) at com.myapp.IinkLayer.access$100(IinkLayer.java:49) at com.myapp.IinkLayer$1.contentChanged(IinkLayer.java:154) at com.myscript.iink.Editor$3.accept(Editor.java:152) at com.myscript.iink.Editor$3.accept(Editor.java:148) at com.myscript.iink.ListenerList.forEach(ListenerList.java:50) at com.myscript.iink.Editor.contentChanged(Editor.java:147)
Following is the code I use to export the data. It is called directly in the onContentChanged callback. I catch IOExceptions, but the exception being thrown is IllegalStateException.
String jiixData = ""; try { // Export the whole part data jiixData = editor.export_(null, MimeType.JIIX); } catch (IOException e) { Log.e(TAG, "Export error!", e); return; }
Thank you for your help!
Best Answer
O
Olivier @MyScript
said
over 3 years ago
Dear Nicolas,
currently, the contentChanged is triggered each time the "content changes", such as a new stroke added, a new partial result available... so it can be several times per second.
On the other side, editor.waitForIdle() will block the thread until the editor is in idle...you then understand it shall never be called in the contentChanged.
My recommendation is simply that the waitForIdle is called just before the export function is called. There is no reason this doesn't work.
currently, the contentChanged is triggered each time the "content changes", such as a new stroke added, a new partial result available... so it can be several times per second.
On the other side, editor.waitForIdle() will block the thread until the editor is in idle...you then understand it shall never be called in the contentChanged.
My recommendation is simply that the waitForIdle is called just before the export function is called. There is no reason this doesn't work.
Best regards,
Olivier
N
Nicolas Morin
said
over 3 years ago
Hi Olivier,
To simplify things, I did a test with the project GetStarted from the sample files. I added waitForIdle() in the callback for contentChanged() so that the callback now looks as follows:
@Override
public void contentChanged(Editor editor, String[] blockIds)
{
editor.waitForIdle(); // Only this line was added
invalidateOptionsMenu();
invalidateIconButtons();
}
With this code, iink processing stops responding after the first stroke. It is still possible to draw strokes, but the conversion preview is never displayed and tapping the "convert" button will cause the app to stop responding (probably UI thread waiting for Editor thread which is in a deadlock as below).
My guess is that the Editor processing runs in its own thread and that contentChanged() is called on that thread, so if we call waitForIdle() there, the Editor ends up waiting for itself and waitForIdle() never returns.
We are thinking that maybe we should call Export on a thread different from the one calling contentChanged(), but do you have a better suggestion?
Thanks!
O
Olivier @MyScript
said
over 3 years ago
Dear Nicolas,
thank you your question.
Currently, considering the message "processing may not be over" and the fact that you did not use the "waitForIdle", I would tend yo think this is reason.
Indeed, depending on the ink that is provided (number of strokes, language, type of part -Diagram, Text...-), the processing time may be (very) long. Please add the waitForIdle, and let us know if you still face the behavior.
On your side, if you do not see any reason the processing takes so long, please provide us with the ink, the type of part your are creating and the configuration of your editor.
Nicolas Morin
I am trying to export the Part data as JIIX data in the Editor's callback for onContentChanged. It usually works, but I sometimes get the following exception. Do you have any idea about what's going wrong and what I could do to fix the issue? I tried adding a call to Editor.waitForIdle() before calling export(), but the call never returns and the app hangs if I do that.
2021-05-11 14:52:31.109 19696-19822/com.myapp E/AndroidRuntime: FATAL EXCEPTION: Thread-2361
Process: com.myapp, PID: 19696
java.lang.IllegalStateException: export operation failed, processing may not be over
at com.myscript.iink.NativeFunctions.doExport1(Native Method)
at com.myscript.iink.Editor.export_(Editor.java:971)
at com.myapp.IinkLayer.processContentChanged(IinkLayer.java:478)
at com.myapp.IinkLayer.access$100(IinkLayer.java:49)
at com.myapp.IinkLayer$1.contentChanged(IinkLayer.java:154)
at com.myscript.iink.Editor$3.accept(Editor.java:152)
at com.myscript.iink.Editor$3.accept(Editor.java:148)
at com.myscript.iink.ListenerList.forEach(ListenerList.java:50)
at com.myscript.iink.Editor.contentChanged(Editor.java:147)
Following is the code I use to export the data. It is called directly in the onContentChanged callback. I catch IOExceptions, but the exception being thrown is IllegalStateException.
String jiixData = "";
try {
// Export the whole part data
jiixData = editor.export_(null, MimeType.JIIX);
} catch (IOException e) {
Log.e(TAG, "Export error!", e);
return;
}
Thank you for your help!
Dear Nicolas,
currently, the contentChanged is triggered each time the "content changes", such as a new stroke added, a new partial result available... so it can be several times per second.
On the other side, editor.waitForIdle() will block the thread until the editor is in idle...you then understand it shall never be called in the contentChanged.
My recommendation is simply that the waitForIdle is called just before the export function is called. There is no reason this doesn't work.
Best regards,
Olivier
- Oldest First
- Popular
- Newest First
Sorted by Newest FirstOlivier @MyScript
Dear Nicolas,
currently, the contentChanged is triggered each time the "content changes", such as a new stroke added, a new partial result available... so it can be several times per second.
On the other side, editor.waitForIdle() will block the thread until the editor is in idle...you then understand it shall never be called in the contentChanged.
My recommendation is simply that the waitForIdle is called just before the export function is called. There is no reason this doesn't work.
Best regards,
Olivier
Nicolas Morin
Hi Olivier,
To simplify things, I did a test with the project GetStarted from the sample files. I added waitForIdle() in the callback for contentChanged() so that the callback now looks as follows:
With this code, iink processing stops responding after the first stroke. It is still possible to draw strokes, but the conversion preview is never displayed and tapping the "convert" button will cause the app to stop responding (probably UI thread waiting for Editor thread which is in a deadlock as below).
My guess is that the Editor processing runs in its own thread and that contentChanged() is called on that thread, so if we call waitForIdle() there, the Editor ends up waiting for itself and waitForIdle() never returns.
We are thinking that maybe we should call Export on a thread different from the one calling contentChanged(), but do you have a better suggestion?
Thanks!
Olivier @MyScript
Dear Nicolas,
thank you your question.
Currently, considering the message "processing may not be over" and the fact that you did not use the "waitForIdle", I would tend yo think this is reason.
Indeed, depending on the ink that is provided (number of strokes, language, type of part -Diagram, Text...-), the processing time may be (very) long. Please add the waitForIdle, and let us know if you still face the behavior.
On your side, if you do not see any reason the processing takes so long, please provide us with the ink, the type of part your are creating and the configuration of your editor.
Best regards,
Olivier
1 person likes this