first question on stackoverflow, was hoping to get some help with this issue. If you take a look at the following EffectManager class, I am getting an assertion failure on _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) when an effectmanager instance is deallocated.
It has something to do with trying to free the memory of the effectsmap, if I never insert the effect into the map I don't run into this problem.
it will also work fine if I use a base STL map, ie
typedef std::map<std::wstring, ID3DXEffect*> EffectsMap;
class EffectManager
{
public:
typedef boost::ptr_map<std::wstring, ID3DXEffect> EffectsMap;
EffectManager();
~EffectManager();
void init();
ID3DXEffect *loadEffect(LPDIRECT3DDEVICE9 d3ddev, std::wstring effectfile);
private:
std::shared_ptr<EffectsMap> effects_;
};
EffectManager::EffectManager() : effects_(NULL)
{
}
EffectManager::~EffectManager()
{
for(auto it = effects_->begin(); it != effects_->end(); it++){
it->second->Release();
}
}
void EffectManager::init()
{
effects_ = std::shared_ptr<EffectsMap>(new EffectsMap());
}
ID3DXEffect *EffectManager::loadEffect(LPDIRECT3DDEVICE9 d3ddev, std::wstring effectfile)
{
if(!effects_)
return NULL;
ID3DXEffect *effect;
if(effects_->count(effectfile)){
effect = effects_->find(effectfile)->second;
} else {
D3DXCreateEffectFromFile(d3ddev, effectfile.c_str(), NULL, NULL, D3DXFX_NOT_CLONEABLE, NULL, &effect, NULL);
effects_->insert(effectfile, effect);
}
return effect;
}