Fix for Crashes in DynamicTexture::setUpdateRect()
by Ed Zavada · in Torque Game Engine · 11/28/2007 (1:48 pm) · 0 replies
When built with Visual Studio 2003 (v7.1.3088), I get a crash bug that appears to be caused by the compiler generating incorrect code in at least 2 places. I blame the compiler because this appears to be correct C++ code using overloading of a typecast operator. This results in a memory stomp and occasional crashes.
First, you need to add a new accessor method to the TextureHandle class to fetch the object member, which is what the typecast was overridden to do.
In engine/dgl/gTexManager.h, on line 410, add the new method in bold:
In engine/dgl/gDynamicTexture.cc, on line 165, change
to:
Then in engine/gui/shiny/guiEffectCanvas.cc, function GuiEffectCanvas::canvasResized(), on line 176, change
to:
Those are the only spots I've confirmed as crashing, but you might want to change any typecast of TextureHandle to TextureObject. Easiest way to do this is to comment out the operator TextureObject*() at gTextManager.h:410, then recompile and let the compiler find them all for you. I had 163 addition locations to fix, many of which were implicit typecasts and seemed to work fine. You could go through that list and only fix the explicit ones, then uncomment the operator TextureObject*() again and rebuild, or you could replace all of them.
The full list is too big to post. Email me if you want it.
First, you need to add a new accessor method to the TextureHandle class to fetch the object member, which is what the typecast was overridden to do.
In engine/dgl/gTexManager.h, on line 410, add the new method in bold:
operator TextureObject*() { return object; }
[b]TextureObject* getTextureObject() { return object; }[/b]In engine/dgl/gDynamicTexture.cc, on line 165, change
// DON'T USE mUpdateRect here // Note that this looks a bit funny, this is because grabbing pixels results in // the rows getting flipped, to adjust for this, the texture coordinates must be flipped TextureObject *obj = (TextureObject *)mTextureHandle;
to:
// DON'T USE mUpdateRect here // Note that this looks a bit funny, this is because grabbing pixels results in // the rows getting flipped, to adjust for this, the texture coordinates must be flipped TextureObject *obj = mTextureHandle->getTextureObject(); // ERZ change to fix crash bug
Then in engine/gui/shiny/guiEffectCanvas.cc, function GuiEffectCanvas::canvasResized(), on line 176, change
TextureObject *obj = (TextureObject *)mFeedbackTexture.getTextureHandle();
to:
TextureObject *obj = mFeedbackTexture.getTextureHandle().getTextureObject(); // ERZ change to fix crash
Those are the only spots I've confirmed as crashing, but you might want to change any typecast of TextureHandle to TextureObject. Easiest way to do this is to comment out the operator TextureObject*() at gTextManager.h:410, then recompile and let the compiler find them all for you. I had 163 addition locations to fix, many of which were implicit typecasts and seemed to work fine. You could go through that list and only fix the explicit ones, then uncomment the operator TextureObject*() again and rebuild, or you could replace all of them.
The full list is too big to post. Email me if you want it.