Our artists work with very big models and we frequently experienced crashes with the exporter due to large memory usage. We noticed that using texture compression actually increased memory usage. It seems that the exporter allocates memory for all the images first, then compresses them at the end, which creates more memory, since the exporter keeps a reference to the original uncompressed image data.
I've modified the exporter to handle image data differently. When the image is initially allocated, the exporter will check if compression is enabled. If so, it will compress the image immediately, and free up the uncompressed data. This drastically decreases the memory usage of the exporter. We have been using these changes for almost 6 months now and have not experienced any crashes due to memory usage.
Here is an outline of the changes I made:
- Created a TextureCompressor class that is used by MtlKeeper to compress individual textures. It will only be allocated if compression is enabled.
- osgconv.h/.cpp is not needed anymore and can be removed
- Data allocation mode of osg::Image objects is set to USE_NEW_DELETE, instead of being manually deleted by the MtlKeeper class.
- When a texture is created and compression is enabled, the texture will be immediately compressed. OSG will internally free the uncompressed data.
- MtlKeeper does not keep a reference to the image data anymore. I noticed in the code comments that this was required because it would cause a crash, but we have not experienced any problems at all.