PDA

View Full Version : Core dumped - clan::SoundOutput_Impl::mixer_thread()



rombust
12-09-2013, 08:11 AM
( Restored deleted thread from daltomi (http://www.rtsoft.com/forums/member.php?92464-daltomi) )

I was testing a few things.
When "SoundOutput" has no parameters the example fails.
When have parameters, it works fine, for example: SoundOutput so(44100)

Then this example does not work, Segmentation fault.



Code:
#include <ClanLib/core.h>
#include <ClanLib/application.h>
#include <ClanLib/sound.h>

static int AppMain(const std::vector<std::string>& args)
{
clan::SetupCore setupCore;
clan::SetupSound setupSound;
clan::SoundOutput soundOutput;

clan::SoundBuffer sound("click.ogg");
sound.play();

return 0;
}

clan::Application app(&AppMain);
The difference in the definition of SoundOutput lies here:



Code:

SoundBuffer_Session SoundBuffer::prepare(bool looping, SoundOutput *output)
{
SoundOutput current_output = Sound::get_current_output();
if (output == 0) output = &current_output;

MutexSection mutex_lock(&impl->mutex);
return SoundBuffer_Session(*this, looping, *output);
}
Value current_output:


Code:

$1 = {_vptr.SoundOutput = 0x7ffff7bd3b70 <vtable for clan::SoundOutput+16>, impl = std::shared_ptr (empty) 0x0}Then current_output->impl is 0x0.
Later:


Code:

void SoundBuffer_Session::play()
{
if (impl)
{
MutexSection mutex_lock(&impl->mutex);
if (impl->playing) return;
if (impl->provider_session->play())
{
impl->playing = true;
mutex_lock.unlock();
impl->output.impl->play_session(*this);
}
}
}

Code:

(gdb) p impl->output.impl
$6 = std::shared_ptr (empty) 0x0
Where "output.impl" is equal to "current_output.impl(0x0)".
Then it calls a:


Code:

void SoundOutput_Impl::play_session(SoundBuffer_Session &session)
{
MutexSection mutex_lock(&mutex);
sessions.push_back(session);
}
mutex = 0x70(garbage), inside MutexSection call mutex-lock() -> Segmentation fault.

Value current_output when SoundOutput();


Code:

$1 = {_vptr.SoundOutput = 0x7ffff7bd3b70 <vtable for clan::SoundOutput+16>, impl = std::shared_ptr (empty) 0x0}Value current_output when SoundOutput(XXXX);


Code:

$1 = {_vptr.SoundOutput = 0x7ffff7bd3b70 <vtable for clan::SoundOutput+16>, impl = std::shared_ptr (count 2, weak 1) 0x6022a0}Maybe it's a bug.

rombust
12-09-2013, 08:28 AM
... Now to try to remember what I put :)


/// \brief Constructs a null instance
SoundOutput();

/// \brief Constructs a SoundOutput
///
/// \param mixing_frequency = value
/// \param latency = value
SoundOutput(int mixing_frequency, int latency = 50);

Many ClanLib classes, have default constructors like this. This means that the implementation for that class is unset ( std::shared_ptr<SoundOutput_Impl> impl )

Classes that contain this feature are classes that require parameters to initialise them

All these classes contain "is_null()" and "throw_if_null()" functions

This feature allows you to treat the classes as handle objects. For example


class Apple
{
public:
Apple(blah blah blah);
clan::Image m_Image;
}

Apple::Apple(blah blah blah)
{
m_Image = clan::Image(blah blah blah);
}

Ideally all handle object classes should contain



void clan_class::my_function()
{
#ifdef DEBUG
throw_if_null();
#endif
...

}
But that's very boring to implement. Maybe one day we will receive a patch.