Initialize BufferManager from within Mixer
Avoid crashes caused by worker threads accessing the buffer manager before it is initialized. Therefore initialize it from within the Mixer constructor which has the side effect that it gets initialized in console-only rendering mode as well.
This commit is contained in:
@@ -40,7 +40,7 @@ const int BM_INITIAL_BUFFERS = 512;
|
||||
class EXPORT BufferManager
|
||||
{
|
||||
public:
|
||||
static void init();
|
||||
static void init( fpp_t framesPerPeriod );
|
||||
static sampleFrame * acquire();
|
||||
static void release( sampleFrame * buf );
|
||||
static void refresh();
|
||||
|
||||
@@ -34,18 +34,18 @@ QAtomicInt BufferManager::s_releasedIndex = 0;
|
||||
int BufferManager::s_size;
|
||||
|
||||
|
||||
void BufferManager::init()
|
||||
void BufferManager::init( fpp_t framesPerPeriod )
|
||||
{
|
||||
s_available = MM_ALLOC( sampleFrame*, BM_INITIAL_BUFFERS );
|
||||
s_released = MM_ALLOC( sampleFrame*, BM_INITIAL_BUFFERS );
|
||||
|
||||
int c = engine::mixer()->framesPerPeriod() * BM_INITIAL_BUFFERS;
|
||||
int c = framesPerPeriod * BM_INITIAL_BUFFERS;
|
||||
sampleFrame * b = MM_ALLOC( sampleFrame, c );
|
||||
|
||||
for( int i = 0; i < BM_INITIAL_BUFFERS; ++i )
|
||||
{
|
||||
s_available[ i ] = b;
|
||||
b += engine::mixer()->framesPerPeriod();
|
||||
b += framesPerPeriod;
|
||||
}
|
||||
s_availableIndex = BM_INITIAL_BUFFERS - 1;
|
||||
s_size = BM_INITIAL_BUFFERS;
|
||||
|
||||
@@ -118,6 +118,9 @@ Mixer::Mixer() :
|
||||
m_fifo = new fifo( 1 );
|
||||
}
|
||||
|
||||
// now that framesPerPeriod is fixed initialize global BufferManager
|
||||
BufferManager::init( m_framesPerPeriod );
|
||||
|
||||
m_workingBuf = (sampleFrame*) MemoryHelper::alignedMalloc( m_framesPerPeriod *
|
||||
sizeof( sampleFrame ) );
|
||||
for( int i = 0; i < 3; i++ )
|
||||
|
||||
@@ -76,7 +76,6 @@
|
||||
#include "DataFile.h"
|
||||
#include "song.h"
|
||||
#include "LmmsPalette.h"
|
||||
#include "BufferManager.h"
|
||||
|
||||
static inline QString baseName( const QString & _file )
|
||||
{
|
||||
@@ -440,9 +439,6 @@ int main( int argc, char * * argv )
|
||||
// init central engine which handles all components of LMMS
|
||||
engine::init();
|
||||
|
||||
// init buffer manager - has to be done after fpp is known
|
||||
BufferManager::init();
|
||||
|
||||
splashScreen.hide();
|
||||
|
||||
// re-intialize RNG - shared libraries might have srand() or
|
||||
@@ -509,6 +505,7 @@ int main( int argc, char * * argv )
|
||||
{
|
||||
// we're going to render our song
|
||||
engine::init( false );
|
||||
|
||||
printf( "loading project...\n" );
|
||||
engine::getSong()->loadProject( file_to_load );
|
||||
printf( "done\n" );
|
||||
|
||||
Reference in New Issue
Block a user