- Fix bug in CSceneNodeAnimatorCollisionResponse::setWorld as found by Quillraven.

- Fix simliar bugs where object have been dropped accidentally in set functions in many places


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2417 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2009-06-10 20:13:37 +00:00
parent f598ea9265
commit 2391338b57
15 changed files with 104 additions and 103 deletions

View File

@ -305,6 +305,8 @@ void CGUIButton::setOverrideFont(IGUIFont* font)
//! Sets an image which should be displayed on the button when it is in normal state.
void CGUIButton::setImage(video::ITexture* image)
{
if (image)
image->grab();
if (Image)
Image->drop();
@ -315,9 +317,6 @@ void CGUIButton::setImage(video::ITexture* image)
ImageRect = core::rect<s32>(core::position2d<s32>(0,0), signedSize);
}
if (Image)
Image->grab();
if (!PressedImage)
setPressedImage(Image);
}
@ -326,15 +325,14 @@ void CGUIButton::setImage(video::ITexture* image)
//! Sets the image which should be displayed on the button when it is in its normal state.
void CGUIButton::setImage(video::ITexture* image, const core::rect<s32>& pos)
{
if (image)
image->grab();
if (Image)
Image->drop();
Image = image;
ImageRect = pos;
if (Image)
Image->grab();
if (!PressedImage)
setPressedImage(Image, pos);
}
@ -343,6 +341,9 @@ void CGUIButton::setImage(video::ITexture* image, const core::rect<s32>& pos)
//! Sets an image which should be displayed on the button when it is in pressed state.
void CGUIButton::setPressedImage(video::ITexture* image)
{
if (image)
image->grab();
if (PressedImage)
PressedImage->drop();
@ -352,23 +353,19 @@ void CGUIButton::setPressedImage(video::ITexture* image)
core::dimension2di signedSize(image->getOriginalSize());
PressedImageRect = core::rect<s32>(core::position2d<s32>(0,0), signedSize);
}
if (PressedImage)
PressedImage->grab();
}
//! Sets the image which should be displayed on the button when it is in its pressed state.
void CGUIButton::setPressedImage(video::ITexture* image, const core::rect<s32>& pos)
{
if (image)
image->grab();
if (PressedImage)
PressedImage->drop();
PressedImage = image;
PressedImageRect = pos;
if (PressedImage)
PressedImage->grab();
}

View File

@ -90,6 +90,8 @@ void CGUIContextMenu::setSubMenu(u32 index, CGUIContextMenu* menu)
if (index >= Items.size())
return;
if (menu)
menu->grab();
if (Items[index].SubMenu)
Items[index].SubMenu->drop();
@ -98,7 +100,6 @@ void CGUIContextMenu::setSubMenu(u32 index, CGUIContextMenu* menu)
if (Items[index].SubMenu)
{
menu->grab();
menu->AllowFocus = false;
if ( Environment->getFocus() == menu )
{

View File

@ -597,6 +597,8 @@ u32 CGUIListBox::addItem(const wchar_t* text, s32 icon)
void CGUIListBox::setSpriteBank(IGUISpriteBank* bank)
{
if ( bank == IconBank )
return;
if (IconBank)
IconBank->drop();

View File

@ -40,14 +40,12 @@ CGUIMeshViewer::~CGUIMeshViewer()
//! sets the mesh to be shown
void CGUIMeshViewer::setMesh(scene::IAnimatedMesh* mesh)
{
if (mesh)
mesh->grab();
if (Mesh)
Mesh->drop();
Mesh = mesh;
if (!Mesh)
return;
else
Mesh->grab();
/* This might be used for proper transformation etc.
core::vector3df center(0.0f,0.0f,0.0f);

View File

@ -205,13 +205,12 @@ void CGUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which)
if ((u32)which >= EGDS_COUNT)
return;
if (font)
font->grab();
if (Fonts[which])
Fonts[which]->drop();
Fonts[which] = font;
if (Fonts[which])
Fonts[which]->grab();
}
@ -225,12 +224,12 @@ IGUISpriteBank* CGUISkin::getSpriteBank() const
//! set a new sprite bank or remove one by passing 0
void CGUISkin::setSpriteBank(IGUISpriteBank* bank)
{
if (SpriteBank)
SpriteBank->drop();
if (bank)
bank->grab();
if (SpriteBank)
SpriteBank->drop();
SpriteBank = bank;
}

View File

@ -80,12 +80,12 @@ void CGUISpriteBank::setTexture(u32 index, video::ITexture* texture)
while (index >= Textures.size())
Textures.push_back(0);
if (Textures[index])
Textures[index]->drop();
if (texture)
texture->grab();
if (Textures[index])
Textures[index]->drop();
Textures[index] = texture;
}

View File

@ -74,8 +74,8 @@ void CGUITreeViewNode::clearChilds()
}
IGUITreeViewNode* CGUITreeViewNode::addChildBack(
const wchar_t* text,
const wchar_t* icon /*= 0*/,
const wchar_t* text,
const wchar_t* icon /*= 0*/,
s32 imageIndex /*= -1*/,
s32 selectedImageIndex /*= -1*/,
void* data /*= 0*/,
@ -97,9 +97,9 @@ IGUITreeViewNode* CGUITreeViewNode::addChildBack(
return newChild;
}
IGUITreeViewNode* CGUITreeViewNode::addChildFront(
const wchar_t* text,
const wchar_t* icon /*= 0*/,
IGUITreeViewNode* CGUITreeViewNode::addChildFront(
const wchar_t* text,
const wchar_t* icon /*= 0*/,
s32 imageIndex /*= -1*/,
s32 selectedImageIndex /*= -1*/,
void* data /*= 0*/,
@ -121,10 +121,10 @@ IGUITreeViewNode* CGUITreeViewNode::addChildFront(
return newChild;
}
IGUITreeViewNode* CGUITreeViewNode::insertChildAfter(
IGUITreeViewNode* other,
const wchar_t* text,
const wchar_t* icon /*= 0*/,
IGUITreeViewNode* CGUITreeViewNode::insertChildAfter(
IGUITreeViewNode* other,
const wchar_t* text,
const wchar_t* icon /*= 0*/,
s32 imageIndex /*= -1*/,
s32 selectedImageIndex /*= -1*/,
void* data /*= 0*/,
@ -155,10 +155,10 @@ IGUITreeViewNode* CGUITreeViewNode::insertChildAfter(
return newChild;
}
IGUITreeViewNode* CGUITreeViewNode::insertChildBefore(
IGUITreeViewNode* other,
const wchar_t* text,
const wchar_t* icon /*= 0*/,
IGUITreeViewNode* CGUITreeViewNode::insertChildBefore(
IGUITreeViewNode* other,
const wchar_t* text,
const wchar_t* icon /*= 0*/,
s32 imageIndex /*= -1*/,
s32 selectedImageIndex /*= -1*/,
void* data /*= 0*/,
@ -421,10 +421,10 @@ bool CGUITreeViewNode::isVisible() const
//! constructor
CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent,
CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool clip,
bool drawBack,bool scrollBarVertical, bool scrollBarHorizontal)
: IGUITreeView( environment, parent, id, rectangle ),
: IGUITreeView( environment, parent, id, rectangle ),
Root(0), Selected(0),
ItemHeight( 0 ),
IndentWidth( 0 ),
@ -452,7 +452,7 @@ CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent,
if ( scrollBarVertical )
{
ScrollBarV = new CGUIScrollBar( false, Environment, this, 0,
core::rect<s32>( RelativeRect.getWidth() - s,
core::rect<s32>( RelativeRect.getWidth() - s,
0,
RelativeRect.getWidth(),
RelativeRect.getHeight() - (scrollBarHorizontal ? s : 0 )
@ -539,7 +539,7 @@ void CGUITreeView::recalculateItemHeight()
if( IconFont )
{
s32 height = IconFont->getDimension( L" " ).Height;
s32 height = IconFont->getDimension( L" " ).Height;
if( height > ItemHeight )
{
ItemHeight = height;
@ -658,7 +658,7 @@ bool CGUITreeView::OnEvent( const SEvent &event )
}
Selecting = false;
Environment->removeFocus( this );
Environment->removeFocus( this );
mouseAction( event.MouseInput.X, event.MouseInput.Y );
return true;
break;
@ -728,7 +728,7 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ )
Selected = hitNode;
}
if( hitNode && !onlyHover
if( hitNode && !onlyHover
&& xpos < hitNode->getLevel() * IndentWidth
&& xpos > ( hitNode->getLevel() - 1 ) * IndentWidth
&& hitNode->hasChilds() )
@ -804,7 +804,7 @@ void CGUITreeView::draw()
clipRect );
}
// draw the border
// draw the border
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect,
clipRect );
@ -953,10 +953,10 @@ void CGUITreeView::draw()
index = node->getImageIndex();
}
ImageList->draw(
index,
core::position2d<s32>(
textRect.UpperLeftCorner.X,
textRect.UpperLeftCorner.Y + ( ( textRect.getHeight() - ImageList->getImageSize().Height ) >> 1 ) ),
index,
core::position2d<s32>(
textRect.UpperLeftCorner.X,
textRect.UpperLeftCorner.Y + ( ( textRect.getHeight() - ImageList->getImageSize().Height ) >> 1 ) ),
&clientClip );
iconWidth += ImageList->getImageSize().Width + 3;
textRect.UpperLeftCorner.X += ImageList->getImageSize().Width + 3;
@ -976,7 +976,7 @@ void CGUITreeView::draw()
textRect.UpperLeftCorner.X -= iconWidth;
}
// draw the lines if neccessary
// draw the lines if neccessary
if( LinesVisible )
{
core::rect<s32> rc;
@ -997,7 +997,7 @@ void CGUITreeView::draw()
clipRect );
if( node->getParent() != Root )
{
{
// vertical line
if( node == node->getParent()->getFirstChild() )
{
@ -1012,7 +1012,7 @@ void CGUITreeView::draw()
clipRect );
// the vertical lines of all parents
IGUITreeViewNode* nodeTmp = node->getParent();
IGUITreeViewNode* nodeTmp = node->getParent();
rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 );
for( s32 n = 0; n < node->getLevel() - 2; ++n )
{
@ -1046,7 +1046,9 @@ void CGUITreeView::setIconFont( IGUIFont* font )
{
s32 height;
if( IconFont )
if ( font )
font->grab();
if ( IconFont )
{
IconFont->drop();
}
@ -1054,12 +1056,11 @@ void CGUITreeView::setIconFont( IGUIFont* font )
IconFont = font;
if( IconFont )
{
height = IconFont->getDimension( L" " ).Height;
height = IconFont->getDimension( L" " ).Height;
if( height > ItemHeight )
{
ItemHeight = height;
}
IconFont->grab();
}
}
@ -1067,6 +1068,8 @@ void CGUITreeView::setIconFont( IGUIFont* font )
//! The default is 0 (no images).
void CGUITreeView::setImageList( IGUIImageList* imageList )
{
if (imageList )
imageList->grab();
if( ImageList )
{
ImageList->drop();
@ -1079,7 +1082,6 @@ void CGUITreeView::setImageList( IGUIImageList* imageList )
{
ItemHeight = ImageList->getImageSize().Height + 1;
}
ImageList->grab();
}
}

View File

@ -18,7 +18,7 @@ namespace irr
//! constructor
CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
Timer(0), CursorControl(0), UserReceiver(params.EventReceiver), Logger(0), Operator(0),
FileSystem(0), InputReceivingSceneManager(0), CreationParams(params)
{
@ -82,7 +82,7 @@ void CIrrDeviceStub::createGUIAndScene()
#ifdef _IRR_COMPILE_WITH_GUI_
// create gui environment
GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);
#endif
#endif
// create Scene manager
SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl, GUIEnvironment);
@ -130,7 +130,7 @@ ITimer* CIrrDeviceStub::getTimer()
}
//! Returns the version of the engine.
//! Returns the version of the engine.
const char* CIrrDeviceStub::getVersion() const
{
return IRRLICHT_SDK_VERSION;
@ -225,16 +225,15 @@ IOSOperator* CIrrDeviceStub::getOSOperator()
}
//! Sets the input receiving scene manager.
//! Sets the input receiving scene manager.
void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneManager)
{
if (sceneManager)
sceneManager->grab();
if (InputReceivingSceneManager)
InputReceivingSceneManager->drop();
InputReceivingSceneManager = sceneManager;
if (InputReceivingSceneManager)
InputReceivingSceneManager->grab();
}

View File

@ -48,8 +48,8 @@ void CMeshSceneNode::OnRegisterSceneNode()
{
if (IsVisible)
{
// because this node supports rendering of mixed mode meshes consisting of
// transparent and solid material at the same time, we need to go through all
// because this node supports rendering of mixed mode meshes consisting of
// transparent and solid material at the same time, we need to go through all
// materials, check of what type they are and register this node for the right
// render pass according to that.
@ -62,16 +62,16 @@ void CMeshSceneNode::OnRegisterSceneNode()
// count transparent and solid materials in this scene node
if (ReadOnlyMaterials && Mesh)
{
// count mesh materials
// count mesh materials
for (u32 i=0; i<Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
video::IMaterialRenderer* rnd = mb ? driver->getMaterialRenderer(mb->getMaterial().MaterialType) : 0;
if (rnd && rnd->isTransparent())
if (rnd && rnd->isTransparent())
++transparentCount;
else
else
++solidCount;
if (solidCount && transparentCount)
@ -80,21 +80,21 @@ void CMeshSceneNode::OnRegisterSceneNode()
}
else
{
// count copied materials
// count copied materials
for (u32 i=0; i<Materials.size(); ++i)
{
video::IMaterialRenderer* rnd =
video::IMaterialRenderer* rnd =
driver->getMaterialRenderer(Materials[i].MaterialType);
if (rnd && rnd->isTransparent())
if (rnd && rnd->isTransparent())
++transparentCount;
else
else
++solidCount;
if (solidCount && transparentCount)
break;
}
}
}
// register according to material types counted
@ -119,7 +119,7 @@ void CMeshSceneNode::render()
if (!Mesh || !driver)
return;
bool isTransparentPass =
bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
++PassCount;
@ -162,7 +162,7 @@ void CMeshSceneNode::render()
// only render transparent buffer if this is the transparent render pass
// and solid only in solid pass
if (transparent == isTransparentPass)
if (transparent == isTransparentPass)
{
driver->setMaterial(material);
driver->drawMeshBuffer(mb);
@ -295,14 +295,12 @@ void CMeshSceneNode::setMesh(IMesh* mesh)
if (!mesh)
return; // won't set null mesh
mesh->grab();
if (Mesh)
Mesh->drop();
Mesh = mesh;
copyMaterials();
if (Mesh)
Mesh->grab();
}
@ -358,7 +356,7 @@ void CMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeRe
}
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
/* In this way it is possible to change the materials a mesh causing all mesh scene nodes
/* In this way it is possible to change the materials a mesh causing all mesh scene nodes
referencing this mesh to change too. */
void CMeshSceneNode::setReadOnlyMaterials(bool readonly)
{
@ -378,7 +376,7 @@ ISceneNode* CMeshSceneNode::clone(ISceneNode* newParent, ISceneManager* newManag
if (!newParent) newParent = Parent;
if (!newManager) newManager = SceneManager;
CMeshSceneNode* nb = new CMeshSceneNode(Mesh, newParent,
CMeshSceneNode* nb = new CMeshSceneNode(Mesh, newParent,
newManager, ID, RelativeTranslation, RelativeRotation, RelativeScale);
nb->cloneMembers(this, newManager);

View File

@ -286,10 +286,10 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
MeshName = SceneManager->getMeshCache()->getMeshFilename( mesh );
mesh->grab();
deleteTree();
Mesh = mesh;
Mesh->grab();
u32 beginTime = os::Timer::getRealTime();
@ -311,7 +311,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
{
IMeshBuffer* b = mesh->getMeshBuffer(i);
if (b->getVertexCount() && b->getIndexCount())
if (b->getVertexCount() && b->getIndexCount())
{
Materials.push_back(b->getMaterial());
@ -343,7 +343,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
for ( i=0; i < mesh->getMeshBufferCount(); ++i)
{
b = mesh->getMeshBuffer(i);
if (b->getVertexCount() && b->getIndexCount())
if (b->getVertexCount() && b->getIndexCount())
{
meshReserve += 1;
}
@ -355,7 +355,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
{
b = mesh->getMeshBuffer(i);
if (b->getVertexCount() && b->getIndexCount())
if (b->getVertexCount() && b->getIndexCount())
{
Materials.push_back(b->getMaterial());
LightMapMeshes.push_back(OctTree<video::S3DVertex2TCoords>::SMeshChunk());
@ -388,7 +388,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
{
IMeshBuffer* b = mesh->getMeshBuffer(i);
if (b->getVertexCount() && b->getIndexCount())
if (b->getVertexCount() && b->getIndexCount())
{
Materials.push_back(b->getMaterial());
TangentsMeshes.push_back(OctTree<video::S3DVertexTangents>::SMeshChunk());

View File

@ -72,6 +72,8 @@ IParticleEmitter* CParticleSystemSceneNode::getEmitter()
//! Sets the particle emitter, which creates the particles.
void CParticleSystemSceneNode::setEmitter(IParticleEmitter* emitter)
{
if (emitter == Emitter)
return;
if (Emitter)
Emitter->drop();
@ -161,7 +163,7 @@ IParticleCylinderEmitter* CParticleSystemSceneNode::createCylinderEmitter(
bool outlineOnly, const core::vector3df& direction,
u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
const video::SColor& minStartColor, const video::SColor& maxStartColor,
u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
const core::dimension2df& minStartSize,
const core::dimension2df& maxStartSize )
{

View File

@ -493,8 +493,8 @@ IMeshSceneNode* CSceneManager::addQuake3SceneNode(IMeshBuffer* meshBuffer,
if (!parent)
parent = this;
CQuake3ShaderSceneNode* node = new CQuake3ShaderSceneNode( parent,
this, id, FileSystem,
CQuake3ShaderSceneNode* node = new CQuake3ShaderSceneNode( parent,
this, id, FileSystem,
meshBuffer, shader );
node->drop();
@ -1095,13 +1095,12 @@ ICameraSceneNode* CSceneManager::getActiveCamera() const
//! \param camera: The new camera which should be active.
void CSceneManager::setActiveCamera(ICameraSceneNode* camera)
{
if (camera)
camera->grab();
if (ActiveCamera)
ActiveCamera->drop();
ActiveCamera = camera;
if (ActiveCamera)
ActiveCamera->grab();
}
@ -1579,13 +1578,12 @@ void CSceneManager::drawAll()
void CSceneManager::setLightManager(ILightManager* lightManager)
{
if ( lightManager )
lightManager->grab();
if(LightManager)
LightManager->drop();
LightManager = lightManager;
if(LightManager)
LightManager->grab();
}

View File

@ -118,15 +118,15 @@ core::vector3df CSceneNodeAnimatorCollisionResponse::getEllipsoidTranslation() c
//! the scene node may collide.
void CSceneNodeAnimatorCollisionResponse::setWorld(ITriangleSelector* newWorld)
{
if (World)
World->drop();
if (newWorld)
newWorld->grab();
World = newWorld;
if (World)
World->grab();
if (World)
World->drop();
World = newWorld;
FirstUpdate = true;
}
@ -188,7 +188,7 @@ void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 time
CollisionResultPosition
= SceneManager->getSceneCollisionManager()->getCollisionResultPosition(
World, LastPosition-Translation,
Radius, vel, CollisionTriangle, CollisionPoint, f,
Radius, vel, CollisionTriangle, CollisionPoint, f,
CollisionNode, SlidingSpeed, FallingVelocity);
CollisionOccurred = (CollisionTriangle != RefTriangle);
@ -273,6 +273,9 @@ ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode*
void CSceneNodeAnimatorCollisionResponse::setCollisionCallback(ICollisionCallback* callback)
{
if ( CollisionCallback == callback )
return;
if (CollisionCallback)
CollisionCallback->drop();

View File

@ -253,6 +253,8 @@ void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount,
void CShadowVolumeSceneNode::setShadowMesh(const IMesh* mesh)
{
if ( ShadowMesh == mesh )
return;
if (ShadowMesh)
ShadowMesh->drop();
ShadowMesh = mesh;

View File

@ -1,2 +1,2 @@
Test suite pass at GMT Tue Jun 9 00:45:13 2009
Test suite pass at GMT Wed Jun 10 20:04:22 2009