Skip to content

Commit db1a225

Browse files
Fix for glsl threading crash #97
1 parent 0682ef1 commit db1a225

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/libprojectM/projectM.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ pthread_mutex_t preset_mutex;
6868

6969
projectM::~projectM()
7070
{
71+
void *status;
7172

7273
#ifdef USE_THREADS
7374
std::cout << "[projectM] thread ";
7475
printf("c");
76+
pthread_mutex_lock( &mutex );
7577
running = false;
78+
pthread_mutex_unlock( &mutex );
7679
printf("l");
7780
pthread_cond_signal(&condition);
7881
printf("e");
79-
pthread_mutex_unlock( &mutex );
82+
pthread_join(thread, &status);
8083
printf("a");
8184
pthread_detach(thread);
8285
printf("n");
@@ -381,16 +384,17 @@ static void *thread_callback(void *prjm) {
381384
assert ( m_activePreset2.get() );
382385

383386
#ifdef USE_THREADS
384-
385-
pthread_cond_signal(&condition);
386-
pthread_mutex_unlock( &mutex );
387+
pthread_cond_signal(&condition);
387388
#endif
389+
388390
m_activePreset->Render(*beatDetect, pipelineContext());
389391

390392
#ifdef USE_THREADS
391-
pthread_mutex_lock( &mutex );
393+
// wait for the thread
394+
pthread_mutex_lock( &mutex );
395+
pthread_mutex_unlock( &mutex );
392396
#else
393-
evaluateSecondPreset();
397+
evaluateSecondPreset();
394398
#endif
395399

396400
Pipeline pipeline;
@@ -524,7 +528,6 @@ static void *thread_callback(void *prjm) {
524528
std::cerr << "[projectM] failed to allocate a thread! try building with option USE_THREADS turned off" << std::endl;;
525529
exit(EXIT_FAILURE);
526530
}
527-
pthread_mutex_lock( &mutex );
528531
#endif
529532

530533
/// @bug order of operatoins here is busted

0 commit comments

Comments
 (0)