I got an access violation exception when using irr::video::ETCF_ALWAYS_16_BIT for texture loading from PNG file.
Actually it works fine for most of texture, but it crashes when trying to load a big (2301x2308) texture atlas.
Below is my helper code for loading a texture. When loading icons i would like to force 16bit format(with alpha) to save memory:
Code: Select all
static irr::video::ITexture* LoadIconTextureFromFile(
irr::IrrlichtDevice* dev, const std::string& path, bool use16bit = false )
{
if( !dev ) {
return NULL;
}
irr::video::ITexture* ret = NULL;
irr::video::IVideoDriver* driver = dev->getVideoDriver();
bool flg_mip = driver->getTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS);
bool flg_pow2 = driver->getTextureCreationFlag(irr::video::ETCF_ALLOW_NON_POWER_2);
bool flg_optimized_quality = driver->getTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_QUALITY);
bool flg_optimized_speed = driver->getTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_SPEED);
bool flg_32bit = driver->getTextureCreationFlag(irr::video::ETCF_ALWAYS_32_BIT);
bool flg_16bit = driver->getTextureCreationFlag(irr::video::ETCF_ALWAYS_16_BIT);
driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS, false);
driver->setTextureCreationFlag(irr::video::ETCF_ALLOW_NON_POWER_2, true);
if( use16bit ) {
driver->setTextureCreationFlag(irr::video::ETCF_ALWAYS_16_BIT, true);
driver->setTextureCreationFlag(irr::video::ETCF_ALWAYS_32_BIT, false);
driver->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_QUALITY, false);
driver->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_SPEED, false);
}
if( FileSystem::FileExists(path) ) {
ret = driver->getTexture(path.c_str());
} else {
LOG_ERROR "texture file missing: %s\n", path.c_str() LOG_END;
}
driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS, flg_mip);
driver->setTextureCreationFlag(irr::video::ETCF_ALLOW_NON_POWER_2, flg_pow2);
if( use16bit ) {
driver->setTextureCreationFlag(irr::video::ETCF_ALWAYS_16_BIT, flg_16bit);
driver->setTextureCreationFlag(irr::video::ETCF_ALWAYS_32_BIT, flg_32bit);
driver->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_QUALITY, flg_optimized_speed);
driver->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_SPEED, flg_optimized_quality);
}
return ret;
}
I work both on windows and android, and I get a similar crash on both systems.
They have enough video memory to load the texture (they can load it in 32BIT mode).
My environments are:
Windows
Irrlicht version 1.8.0
Visual Studio 2010 premium
Using OpenGL driver
Android
Irrlicht 1.9.0
Eclipse ADT (using android NDK r10b, ADT Version: 23.0.6.1720515)
Using OpenGL ES 2.0 driver
Any ideas?