diff options
| author | 2014-03-05 16:56:02 -0800 | |
|---|---|---|
| committer | 2014-03-05 16:56:02 -0800 | |
| commit | 9a9916b58fb22da735d18a03beffb24b4d5cd9a3 (patch) | |
| tree | b3ad8af4469c88f93a633e5fea65ccdca308f6d7 | |
| parent | 9c6f41e3eb2258d52480be04dd8916a10f8be8db (diff) | |
| parent | 2383f2200ab0c2dbd71708b5c1fb6af98db408fa (diff) | |
am 2383f220: Merge "Validate objects are from the correct context."
* commit '2383f2200ab0c2dbd71708b5c1fb6af98db408fa':
Validate objects are from the correct context.
| -rw-r--r-- | rs/java/android/renderscript/RenderScript.java | 8 | ||||
| -rw-r--r-- | rs/java/android/renderscript/Script.java | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java index 7db331f0ab0c..eebeaa4ff8cc 100644 --- a/rs/java/android/renderscript/RenderScript.java +++ b/rs/java/android/renderscript/RenderScript.java @@ -1004,6 +1004,14 @@ public class RenderScript { } } + void validateObject(BaseObj o) { + if (o != null) { + if (o.mRS != this) { + throw new RSIllegalArgumentException("Attempting to use an object across contexts."); + } + } + } + void validate() { if (mContext == 0) { throw new RSInvalidStateException("Calling RS with no Context active."); diff --git a/rs/java/android/renderscript/Script.java b/rs/java/android/renderscript/Script.java index a1f228718436..0e46f94a583e 100644 --- a/rs/java/android/renderscript/Script.java +++ b/rs/java/android/renderscript/Script.java @@ -128,6 +128,9 @@ public class Script extends BaseObj { * */ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) { + mRS.validate(); + mRS.validateObject(ain); + mRS.validateObject(aout); if (ain == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); @@ -152,6 +155,9 @@ public class Script extends BaseObj { * */ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v, LaunchOptions sc) { + mRS.validate(); + mRS.validateObject(ain); + mRS.validateObject(aout); if (ain == null && aout == null) { throw new RSIllegalArgumentException( "At least one of ain or aout is required to be non-null."); @@ -187,6 +193,7 @@ public class Script extends BaseObj { */ public void bindAllocation(Allocation va, int slot) { mRS.validate(); + mRS.validateObject(va); if (va != null) { if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 20) { final Type t = va.mType; @@ -263,6 +270,8 @@ public class Script extends BaseObj { * */ public void setVar(int index, BaseObj o) { + mRS.validate(); + mRS.validateObject(o); mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS)); } |