I have tried to add entities into the component definition, then create the instance of the component definition, add those into a model. However, the SketchupApi throw the exception: Access violation reading location 0x0000000000000000 with the function SUEntitiesFill. And the following is code segment.
SUEntitiesRef entities = SU_INVALID;
SUComponentDefinitionRef comp_def = SU_INVALID;
SUEntitiesRef comp_def_entities = SU_INVALID;
SUComponentInstanceRef instance = SU_INVALID;
SUModelGetEntities(model, &entities);
for (int i = 0; i < ObjCount; i++) {
SUSetInvalid(comp_def);
SUSetInvalid(comp_def_entities);
SUSetInvalid(instance);
SU_CALL(SUComponentDefinitionCreate(&comp_def));
SU_CALL(SUComponentDefinitionGetEntities(comp_def, &comp_def_entities));
SU_CALL(SUEntitiesFill(comp_def_entities, input[i], false));
string comp_name = "component_" + std::to_string(i);
SU_CALL(SUComponentDefinitionSetName(comp_def, comp_name.c_str()));
SUComponentBehavior behavior;
behavior.component_always_face_camera = true;
SU_CALL(SUComponentDefinitionSetBehavior(comp_def, &behavior));
SU_CALL(SUModelAddComponentDefinitions(model, 1, &comp_def));
SU_CALL(SUComponentDefinitionCreateInstance(comp_def, &instance));
SU_CALL(SUEntitiesAddInstance(entities, instance, NULL));
}
When I test another way, just add SUGeometryInputRef directly into the model, it works well. And the none error code segment is as follow:
SUEntitiesRef entities = SU_INVALID;
SUModelGetEntities(model, &entities);
for (int i = 0; i<ObjCount; i++) {
SU_CALL(SUEntitiesFill(entities, input[i], false));
}
Could anyone help to check the code with component addition? What’s wrong of my completion?
Thanks in advance!