Hi all,
I am using SketchUp C++ API to convert a sketchup model into a component definition and add it’s instance to another sketchup model. In the following code, i am adding catalogModeRef_k to ImportedSkpModel0.
Crash happens at SUModelSaveToFile(), with error “Exception thrown at 0x00007FFD2DEC3BE5 (SketchUpAPI.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. occurred”
It doesn’t crash if i add only Materials and Component Definitions. Group definitions is causing the crash.
SUModelRef ImportedSkpModel0= SUModelCreateFromFile(.....); // this is working fine
SUModelRef catalogModeRef_k = SUModelCreateFromFile(.....); // this is working fine
if (SUIsValid(catalogModeRef_k))
{
//materials
size_t material_count = 0;
SUModelGetNumMaterials(catalogModeRef_k, &material_count);
size_t material_count_out = 0;
SUMaterialRef* materialRefs = new SUMaterialRef[material_count];
SUModelGetMaterials(catalogModeRef_k, material_count, materialRefs, &material_count_out);
SUResult addmaterials_result = SUModelAddMaterials(ImportedSkpModel0, material_count_out, materialRefs);
// component definition that define component instances but not groups
size_t compdef_count = 0;
SUModelGetNumComponentDefinitions(catalogModeRef_k, &compdef_count);
size_t compdef_count_out = 0;
SUComponentDefinitionRef* compdefs = new SUComponentDefinitionRef[compdef_count];
SUModelGetComponentDefinitions(catalogModeRef_k, compdef_count, compdefs, &compdef_count_out);
SUResult addcompdefs_result = SUModelAddComponentDefinitions(ImportedSkpModel0, compdef_count_out, compdefs);
// component definition that define groups -- adding group defs is causing crash when we save the skp model
size_t groupdef_count = 0;
SUModelGetNumGroupDefinitions(catalogModeRef_k, &groupdef_count);
size_t groupdef_count_out = 0;
SUComponentDefinitionRef* groupdefs = new SUComponentDefinitionRef[groupdef_count];
SUModelGetGroupDefinitions(catalogModeRef_k, groupdef_count, groupdefs, &groupdef_count_out);
SUResult addgroupdefs_result = SUModelAddComponentDefinitions(ImportedSkpModel0, groupdef_count_out, groupdefs);
}
SUResult SaveSkp_result = SU_ERROR_NONE;
if (SUIsValid(ImportedSkpModel0))
{
// save it as a new skp model
SaveSkp_result = SUModelSaveToFile(ImportedSkpModel0, SavePath); // CRASHING AT THIS POINT.
}
You are mixing ownership of entities. You cannot feed the entities that is owned by one model and pass it to another.
In SketchUp, a component can be considered a model. For instance, if you right click a component in SketchUp and choose Save As it will save out a new .skp file. Similar, if you import a .skp file into another model it will appear as a new component definition.
Now - I’m looking through the C API docs, and I’m starting to wonder if we are missing this functionality there…
Maybe I’m looking in the wrong place. But I’ll dig deeper and check back.
As you suggested, I also went through C API. It doesn’t have a method similar to Ruby API, to get component definition from a sketchup model.
I am trying to merge 2 sketchup models(say, A and B) into one new model, using C APIs
I created a new SUModelRef. Then, recursively, populate it’s entities from both A and B.
Everything works fine. But, sometimes it crashes at the final stage when I try to save the new model using SUModelSaveToFile().
Any idea why it happens?
I was trying to debug my visual studio project. But, Sketchup SDK doesn’t have debugging symbols(.pdb files).
Is there anyway I can get .pdb files so that I can debug my project.
As I mentioned before - you should not add entities that belongs to one model to another model. Both models will then own the entities and there will be crashes.
I’ve added a feature request to add this to the API. (SU-38429)
I’m afraid that we cannot provide debug symbols for SketchUp.