|
From: William N. <fir...@ho...> - 2009-01-01 23:56:51
|
> In cases like this I use a pointer:
>
> Py::ExtensionObject<Input> *input_ptr;
>
> and new a Py::ExtensionObject<Input>( input ) when I have it available.
>
> You need to create the the Py::Object to pass it back to python like
> this:
>
> Py::ExtensionObject<Input> an_input_object( Py::asObject( new
> Input(this, hwnd) ) ) );
>
> I've been looking at allowing Py::Object to hold NULL for V6.0.0 - but
> that targeted at Python 3.0.
>
>
> Barry
Ok, I did as you said and used the Py::ExtensionObject, however I seem to be back where I started with object not being deleted :(
The problem seems to be that somehow it thinks it still refrenced when its not, that is when I checked the refrence count before destroying what should be the final refrence it reports a count of 2. Whats more when the object is first created the count seems to start at 2...
Where the object is created
//create voice object
Py::ExtensionObject<SourceVoice> voice(new SourceVoice(sourceVoice, Py::ExtensionObject<Sound>(this), loop));
std::cout << voice.reference_count() << " ";//2???
audio->extensionObject()->AddSourceVoice(voice);//the Audio class maintains a reference (basicly adds to playing set in Audio class)
//start playback
sourceVoice->Start(0);
std::cout << voice.reference_count() << std::endl;//3, as exspected since refrence was 2 before
return voice;//in my tests this return value was not used
}
The objects constructor - I see nothing here to create a 2nd refrence to itself, only an extra refrence to the Sound object
SourceVoice::SourceVoice(IXAudio2SourceVoice *_voice, Py::ExtensionObject<Sound> _sound, bool _isLooping)
:voice(_voice), isLooping(_isLooping), isPaused(false), sound(_sound)
{}
Where the final refrence counts should be removed:
for(std::set<Py::ExtensionObject<SourceVoice>>::iterator it=playing->begin();it!=playing->end();++it)
{
it->extensionObject()->GetVoice()->GetState(&state);
if(state.BuffersQueued <= 0)//finished, we can clear this up
{
//since erasing invalidates the iterator, we add it to a seperate container to delete later, safly
finished->push_back(*it);
}
}
//clear up finished sounds
for(std::vector<Py::ExtensionObject<SourceVoice>>::iterator it=finished->begin();it!=finished->end();++it)
{
playing->erase(*it);
}
//here the last refrence should be deleted, since the python test code never kept the refrence returned before
//and nethier the playing or finsihed list now have a refrence to the SourceVoice object
finished->clear();
_________________________________________________________________
Imagine a life without walls. See the possibilities.
http://clk.atdmt.com/UKM/go/122465943/direct/01/ |