Texture-Files still open?

I am reading more than one 3ds file a time. All files are delivered in a zip-File with a special hirachy, textures are in the same folder with the 3ds. After extracting into a temp-folder and reading them I want to delete the temp-folder to get my system clean again. If I do so I get the message:

The process cannot access the file 'MTX0000.jpg' because it is being used by another process.

model3DsContent.ReadFile(filename, viewPortForXaml);
opening the texture-files without closing them - and when: how can I avoid this failiur?

Al far as I can see I am not using anything else refering to textures.

Thanks for help!
Your problem is caused by ImageBrush that is used in DiffuseMaterial to specify the texture file. When the image file is shown in ImageBrush, WPF locks the file and prevents its deletion.

This can be simply tested with the following:

<Rectangle Width="100" Height="100">
<ImageBrush ImageSource="myImage.jpg" />

In your case I would recommend you that after reading the 3ds file, you go through all the materials in the read 3d objects (use Materials on Reader3ds class) and in case ImageBrush is used in the material, read the image file into memory stream and use it instead of the file on the disk.

This could release the lock on the file - I did not test it, but I think this should at least give the the direction in which to search for the solution.
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)