Create multiple materials same image

I’m trying to write a SKP file using C++ SDK, but I cannot create multiple SUMaterialRef using the same SUTextureRef. My model uses one texture image multiple times with different attributes. If I create only one SUTextureRef with SUTextureCreateFromImageData, and assign it to multiple material, I get an exception in SUModelRelease. Testcase follows. The model is saved with two materials with the same image.
Any idea?

// Create an empty model  
SUModelRef model;
SUSetInvalid(model); 

SU_CALL (SUModelCreate(&model));  

// Single texture
SUTextureRef textureSKP;
SUSetInvalid(textureSKP);

char *imageData = new char[500];
char *point = imageData;
for (int x = 0; x < 10; x++)
	for (int y = 0; y < 10; y++)
	{
		*(point++) = 10*x;
		*(point++) = 10*x;
		*(point++) = 10*x;
	}


SU_CALL(SUTextureCreateFromImageData( &textureSKP,  10, 10, 24, ( const SUByte *) imageData));

delete [] imageData; imageData = NULL;

SUMaterialRef matLocal1, matLocal2;
SUSetInvalid (matLocal1);
SUSetInvalid (matLocal2);

SU_CALL(SUMaterialCreate(&matLocal1));  
SU_CALL(SUMaterialSetName(matLocal1,"Material 1"));  
SU_CALL(SUMaterialSetType(matLocal1, SUMaterialType_Textured));
SU_CALL(SUMaterialSetTexture(matLocal1, textureSKP));


SU_CALL(SUMaterialCreate(&matLocal2));  
SU_CALL(SUMaterialSetName(matLocal2,"Material 2"));  
SU_CALL(SUMaterialSetType(matLocal2, SUMaterialType_Textured));
SU_CALL(SUMaterialSetTexture(matLocal2, textureSKP)); // If I remove this works

SU_CALL(SUModelAddMaterials(model, 1, &matLocal1));
SU_CALL(SUModelAddMaterials(model, 1, &matLocal2)); 

SU_CALL(SUModelSaveToFile(model, "c:\\tmp\\testcase.skp"));  
SU_CALL(SUModelRelease(&model)); // unhandled Exception

SketchUp doesn’t allow multiple materials to share the same textures. The way it works internally is that each material owns its texture.

Thanks, we’ve updated our export to have 1 material - 1 texture

What thomthom says is right and wrong…
A material with a texture owns that texture file, but another material can be made which uses that same texture file.
You just can’t edit it from the Materials Browser if it that material is not the “first-user”.
Editing one presumably edits all such referenced textures ?
You could of course make multiple copies of the texture file using an incrementing file name suffix and use those for each of the textured-materials, then each material will have it’s own texture file.