From 6f4cf0b8885403ead157ae00fd43cf1282331c23 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Tue, 16 Nov 2010 17:37:02 -0800 Subject: Fix ref counting for globals when set from java code. Change-Id: I415b6ddeaab277e60233e905a6bae357cd5193eb --- libs/rs/rsScript.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libs/rs/rsScript.cpp') diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp index 4ffdbfd..efdc626 100644 --- a/libs/rs/rsScript.cpp +++ b/libs/rs/rsScript.cpp @@ -67,6 +67,22 @@ void Script::setVar(uint32_t slot, const void *val, uint32_t len) { } } +void Script::setVarObj(uint32_t slot, ObjectBase *val) { + ObjectBase **destPtr = ((ObjectBase ***)mEnviroment.mFieldAddress)[slot]; + + if (destPtr) { + if (val != NULL) { + val->incSysRef(); + } + if (*destPtr) { + (*destPtr)->decSysRef(); + } + *destPtr = val; + } else { + LOGV("Calling setVarObj on slot = %i which is null. This is dangerous because the script will not hold a ref count on the object.", slot); + } +} + namespace android { namespace renderscript { @@ -103,6 +119,12 @@ void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) { s->setVar(slot, &value, sizeof(value)); } +void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) { + Script *s = static_cast