On 19.05.2006 13:14, res wrote: >> It looks like it's having problems when trying to destroy the >> iGenMeshAnimationControl object. > > Classes that exhibit interfaces *need* to be refcounted. In this case > your flaw is that you have a non-refcounted class whose descendents > expose interfaces, hence need to be ref-counted (actually, they need to > be a complete SCF class). So either you make the base class > SCF-compatible and all or you refactor your code so that the interfaces > are proper refcounted objects.
Perhaps I should explain some more. Basically, there are two things you're doing wrong: 1. You're deleting a refcounted object. 2. You have a circular reference. 1. occurs when you delete those psEffectObj descendants that expose interfaces. It has an interface, so it has to be refcounted properly. Not refcounting psEffectObj is fine, as long as you can guarantee sole ownership by the effect manager. However, since some effect objects expose interfaces you pass around to other places in the engine, you cannot guarantee sole ownership any more. E.g. in this case, when you pass the animation control interface to the GM, the latter will take ownership, too. This also leads us to 2. The GM will keep a ref to the animation control interface; however, in this case the implementation of that interface keeps a ref to the GM: circularity. What now happens when you delete an instance of that object (ket's pretend it's an psEffectObjQuad), you're first deleting an object you don't have complete ownership of (the GM will have a reference). However, in the process of destruction, the GM reference gets releases. This will destroy the GM object, which in turn will release the animation control interface. Now, that causes the dtor of ~psEffectObjQuad being called *again*. The GM ref gets released again, now with an reference to an already-destroyed object, probably causing the crash. So what you should do it to fix both the deletion of a refcounted object and the circular reference. One way would be to change the implementation so that you don't co-inherit from psEffectObj and an interface; rather, separate the interface implementation into a separate class (to which the effect object should probably keep a ref). That way you can also move the GM ref out of the animation control implementation and avoid a circular ref. -f.r.
signature.asc
Description: OpenPGP digital signature
