Fix T61956: Errors when instancing grease pencil objects

The problem was not only for instances, but for particles too, and produced segment fault.

For some reason due any internal modification of how duplicated objects are generated, the duplicated object are not available when the draw manager try to use runtime data.

Now, before drawing the particle or the instance, the pointers of the duplicated objects are reassigned to the original "real object" to get full access to runtime data.
This commit is contained in:
Antonioya
2019-02-26 20:28:06 +01:00
parent 92766fb965
commit 930d0070b6
3 changed files with 27 additions and 0 deletions

View File

@@ -68,6 +68,8 @@ tGPencilObjectCache *gpencil_object_cache_add(
cache_elem->ob = ob;
cache_elem->gpd = (bGPdata *)ob->data;
strcpy(cache_elem->name, ob->id.name);
copy_v3_v3(cache_elem->loc, ob->obmat[3]);
copy_m4_m4(cache_elem->obmat, ob->obmat);
cache_elem->idx = *gp_cache_used;

View File

@@ -639,6 +639,30 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
void GPENCIL_cache_finish(void *vedata)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
tGPencilObjectCache *cache_ob = NULL;
Object *ob = NULL;
GHash *gh_objects = BLI_ghash_str_new(__func__);
/* create hash of real object (non duplicated) */
for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
cache_ob = &stl->g_data->gp_object_cache[i];
if (!cache_ob->is_dup_ob) {
ob = cache_ob->ob;
BLI_ghash_insert(gh_objects, ob->id.name, cache_ob->ob);
}
}
/* reasign duplicate objects because memory for particles is not available
* and need to use the original datablock and runtime data */
for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
cache_ob = &stl->g_data->gp_object_cache[i];
if (cache_ob->is_dup_ob) {
Object *ob_orig = (Object *)BLI_ghash_lookup(gh_objects, cache_ob->name);
cache_ob->ob = ob_orig;
cache_ob->gpd = (bGPdata *)ob_orig->data;
}
}
BLI_ghash_free(gh_objects, NULL, NULL);
/* draw particles */
DRW_gpencil_populate_particles(&e_data, vedata);

View File

@@ -69,6 +69,7 @@ typedef struct tGPencilObjectCache {
struct Object *ob;
struct bGPdata *gpd;
int idx; /*original index, can change after sort */
char name[66];
/* effects */
bool has_fx;