diff options
| author | 2010-09-28 15:45:45 -0700 | |
|---|---|---|
| committer | 2010-09-29 16:58:17 -0700 | |
| commit | 01f0ad7c13b8878c2167bff10ea875d7509edca5 (patch) | |
| tree | a23bced149e474da62c7da992015a5e3163486f9 /libs/rs/rsScriptC.cpp | |
| parent | 3ebb1ba50c9b98e5303eb21ed6fa488c3f9bd632 (diff) | |
Fix clear() operation for rsScriptC.
- This removes a memory leak where some elements were not getting tracked
properly (and then triggering an assert when a context is destroyed).
- Convert ScriptCState to use a tracked object reference for mScript.
- Add a missing clear to FontState.
- Clean up synchronization in RSTest so that our graphics context outlives
any subtest context.
Change-Id: I0d5768c4d2f8810dd1ae2f68b1edd7e150f382fd
Diffstat (limited to 'libs/rs/rsScriptC.cpp')
| -rw-r--r-- | libs/rs/rsScriptC.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index e9621b9a8554..c6418be67f93 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -349,25 +349,29 @@ void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len ScriptCState::ScriptCState() { - mScript = NULL; - clear(); + mScript.clear(); } ScriptCState::~ScriptCState() { - delete mScript; - mScript = NULL; + mScript.clear(); } -void ScriptCState::clear() +void ScriptCState::init(Context *rsc) { + clear(rsc); +} + +void ScriptCState::clear(Context *rsc) +{ + rsAssert(rsc); for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) { mConstantBufferTypes[ct].clear(); mSlotWritable[ct] = false; } - delete mScript; - mScript = new ScriptC(NULL); + mScript.clear(); + mScript.set(new ScriptC(rsc)); } static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name) @@ -503,7 +507,7 @@ namespace renderscript { void rsi_ScriptCBegin(Context * rsc) { ScriptCState *ss = &rsc->mScriptC; - ss->clear(); + ss->clear(rsc); } void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) @@ -522,10 +526,10 @@ RsScript rsi_ScriptCCreate(Context * rsc) { ScriptCState *ss = &rsc->mScriptC; - ScriptC *s = ss->mScript; - ss->mScript = NULL; + ObjectBaseRef<ScriptC> s = ss->mScript.get(); + ss->mScript.clear(); - ss->runCompiler(rsc, s); + ss->runCompiler(rsc, s.get()); s->incUserRef(); s->setContext(rsc); for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) { @@ -533,8 +537,8 @@ RsScript rsi_ScriptCCreate(Context * rsc) s->mSlotWritable[ct] = ss->mSlotWritable[ct]; } - ss->clear(); - return s; + ss->clear(rsc); + return s.get(); } } |