SUModelSaveToFile() triggers Access violation

sketchup
sdk
development

#1

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.
    }

#2

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.

In the Ruby APi can can do this by using Sketchup::DefinitionList#load: http://ruby.sketchup.com/Sketchup/DefinitionList.html#load-instance_method

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.


#3

Hi Thomas,

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.

Error message at SUModelSaveToFile():

[2017.12.18-10.17.09:895][709]LogWindows: Error: === Critical error: ===
[2017.12.18-10.17.09:895][709]LogWindows: Error:
[2017.12.18-10.17.09:895][709]LogWindows: Error: Fatal error!
[2017.12.18-10.17.09:895][709]LogWindows: Error:
[2017.12.18-10.17.09:895][709]LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x0b658570
[2017.12.18-10.17.09:895][709]LogWindows: Error:
[2017.12.18-10.17.09:895][709]LogWindows: Error: 0x000000000B658570
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022F83BED
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022FE3F60
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022FE695D
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022FF5CF3
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022FA52CF
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022FA4A92
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022D5A75D
[2017.12.18-10.17.09:895][709]LogWindows: Error: SketchUpAPI.dll!0x0000000022D5A698

Further, going into assembly code shows this:

00007FFD1F8F48E6 mov rdx,r14
00007FFD1F8F48E9 mov qword ptr [rsp+268h],rdx
00007FFD1F8F48F1 mov dword ptr [rsp+270h],r14d
00007FFD1F8F48F9 mov rcx,qword ptr [MergedSkpModel]
00007FFD1F8F48FE call qword ptr [__imp_SUModelSaveToFile (07FFD1F9FD3B8h)]
00007FFD1F8F4904 nop — CRASHES HERE.


#4

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.


#5

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.