Fix T46677: OpenSubdiv crashes when witching from simple and CC subdivisions

Crash was happening due to OpenGL free from the non-main thread. Ideally we need
to implement somewhat delayed unused buffer free for OpenSubdiv similar to what we
are doing in GPU module.
This commit is contained in:
Sergey Sharybin 2015-11-03 14:25:42 +05:00
parent 0d0fa446b7
commit 6063790732

@ -1598,7 +1598,8 @@ static void scene_free_unused_opensubdiv_cache(Scene *scene)
ModifierData *md = object->modifiers.last; ModifierData *md = object->modifiers.last;
if (md != NULL && md->type == eModifierType_Subsurf) { if (md != NULL && md->type == eModifierType_Subsurf) {
SubsurfModifierData *smd = (SubsurfModifierData *) md; SubsurfModifierData *smd = (SubsurfModifierData *) md;
bool object_in_editmode = object->mode == OB_MODE_EDIT; const bool object_in_editmode = (object->mode == OB_MODE_EDIT);
const bool use_simple = (smd->subdivType == ME_SIMPLE_SUBSURF);
if (!smd->use_opensubdiv || if (!smd->use_opensubdiv ||
DAG_get_eval_flags_for_object(scene, object) & DAG_EVAL_NEED_CPU) DAG_get_eval_flags_for_object(scene, object) & DAG_EVAL_NEED_CPU)
{ {
@ -1609,13 +1610,21 @@ static void scene_free_unused_opensubdiv_cache(Scene *scene)
ccgSubSurf_free_osd_mesh(smd->emCache); ccgSubSurf_free_osd_mesh(smd->emCache);
} }
} }
if (object_in_editmode && smd->mCache != NULL) { if (smd->mCache != NULL) {
ccgSubSurf_free(smd->mCache); if (object_in_editmode ||
smd->mCache = NULL; ccgSubSurf_getSimpleSubdiv(smd->mCache) != use_simple)
{
ccgSubSurf_free(smd->mCache);
smd->mCache = NULL;
}
} }
if (!object_in_editmode && smd->emCache != NULL) { if (smd->emCache != NULL) {
ccgSubSurf_free(smd->emCache); if (!object_in_editmode ||
smd->emCache = NULL; ccgSubSurf_getSimpleSubdiv(smd->emCache) != use_simple)
{
ccgSubSurf_free(smd->emCache);
smd->emCache = NULL;
}
} }
} }
} }