Texture map image resources are occupied and cannot be deleted

The SetTextureFileName() method in class AIS_TextureShape sets texture maps.
After rendering, then the source image is occupied and cannot be deleted, in version 7.8.1
the same method in version 7.7.0 ,I can do it,
Why?
Have any modifications been made here?
I hope someone can help me.

Dmitrii Pasukhin's picture

Hello, could you please share details about "occupied" and can't be deleted. It is issue with file on filesystem?

which methods did you use before? Could you share code sample?

Best regards, Dmitrii.

 

Summer baby's picture

Handle(AIS_TexturedShape) aTShape = new AIS_TexturedShape(aShape);
aTShape->SetTextureFileName(aTFileName);
aTShape->SetTextureMapOn();
aTShape->SetTextureScale(Standard_True, toScaleU, toScaleV);
aTShape->SetTextureRepeat(Standard_True, toRepeatU, toRepeatV);
aTShape->SetTextureOrigin(Standard_True, originU, originV);
aTShape->SetPolygonOffsets(Aspect_POM_Fill, 0.5);
aTShape->SetDisplayMode(3);

---------------------------------------------------------------------------------------------
After using the above code, the image resources(The local file corresponding to (aTFileName)) are occupied and cannot be deleted

gkv311 n's picture

DRAW script:

pload MODELING VISUALIZATION
box b 100 200 300
vinit View1
vdisplay -dispMode 1 b
vfit
file copy -force [locate_data_file hatch_1.png] tmp.png
vtexture b tmp.png
file delete tmp.png
# error deleting "tmp.png": permission denied

The regression is caused by the patch for '0031956: Visualization - provide Image_AlienPixMap::Save() writing into a memory':

   }
+
+  IWICBitmapFlipRotator* aRotator;
+  bool isTopDown = true;
+  if (aWicImgFactory->CreateBitmapFlipRotator (&aRotator) == S_OK
+   && aRotator->Initialize (aWicSrc, WICBitmapTransformFlipVertical) == S_OK)
+  {
+    isTopDown = false;
+    aWicSrc = aRotator;
+  }
+
   if (aWicSrc->CopyPixels (NULL, (UINT )SizeRowBytes(), (UINT )SizeBytes(), ChangeData()) != S_OK)

IWICBitmapFlipRotator instance is never released leading to a memory leak and locked file.

Possible fix:

-  IWICBitmapFlipRotator* aRotator;
+  Image_ComPtr<IWICBitmapFlipRotator> aRotator;
  bool isTopDown = true;
-  if (aWicImgFactory->CreateBitmapFlipRotator (&aRotator) == S_OK
+  if (aWicImgFactory->CreateBitmapFlipRotator (&aRotator.ChangePtr()) == S_OK
   && aRotator->Initialize (aWicSrc, WICBitmapTransformFlipVertical) == S_OK)
  {
    isTopDown = false;
-    aWicSrc = aRotator;
+    aWicSrc = aRotator.get();
  }
Summer baby's picture

Thank you for your reply
so is this a new bug?

gkv311 n's picture

so is this a new bug?

As you noticed:

After rendering, then the source image is occupied and cannot be deleted, in version 7.8.1 the same method in version 7.7.0 ,I can do it, Why?

This change #31956 had been introduced by OCCT 7.8.0.