Reputation: 1
This is my 3rd question about RenderScript, and I have programed a image processing project more than 3 months with rs. Rs is powerful, I can use parallel kernel which is alike shader of OpenGLES and also I can write serial code to do box blur. It's amazing!
But now, I have a new problem.
It is common to show the effect with dynamic thumbnails on the button before users choose which effect to apply. So I create a thread for each thumbnail of button, and every thread has its own rs and context. Thread create and use allocations by its own rs and context, so the error like "using object with dismatched context" should not occur. Unfortunately, it happened.
FATAL EXCEPTION: AsyncTask #4
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1027)
Caused by: android.support.v8.renderscript.RSInvalidStateException: using object with mismatched context.
at android.support.v8.renderscript.BaseObj.getID(BaseObj.java:66)
at android.support.v8.renderscript.Script.setVar(Script.java:382)
at com.xxxxxxxxxxx.xxxxxxxx.algorithms.filter.Script_BaseFilter.set_gTableTex(ScriptC_BaseFilter.java:280)
…………(not important)
I'm aware that I can not use multithread to render texture with OpenGLES, but I don't read anything like this in rs.
The werridest thing is, sometime some lines of pixel in one thumbnail are replaced by another thumbnial's pixel of the same line!!! Crash is not happened everytime, mostly, big original image or one effect which takes a long time to process has a higher possibility to shut down the activity even whole program.
Is this a bug, or rs can't be invoked by multithread?
Upvotes: 0
Views: 685
Reputation: 1469
The error is not related to multithreading.
Caused by: android.support.v8.renderscript.RSInvalidStateException: using object with mismatched context.
This means a RenderScript object was created in one context then used in a different context. It is not legal to do this. Each context has its unique set of objects. If you need to efficiently move data between them use USAGE_IO_INPUT & USAGE_IO_OUTPUT on the allocations and link them together.
Upvotes: 1