diff --git a/Engine/csound_orc_compile.c b/Engine/csound_orc_compile.c index fd684cb92f3..88be5ae788b 100644 --- a/Engine/csound_orc_compile.c +++ b/Engine/csound_orc_compile.c @@ -1836,14 +1836,15 @@ int csoundCompileTreeInternal(CSOUND *csound, TREE *root, int async) { return CSOUND_ERROR; } - /* now add the instruments with names, assigning them fake instr numbers */ - named_instr_assign_numbers(csound, engineState); + if (engineState != &csound->engineState) { OPDS *ids = csound->ids; /* any compilation other than the first one */ /* merge ENGINE_STATE */ /* lock to ensure thread-safety */ if (!async) { + /* now add the instruments with names, assigning them fake instr numbers */ + named_instr_assign_numbers(csound, engineState); if (!csound->oparms->realtime) csoundLockMutex(csound->API_lock); merge_state(csound, engineState, typeTable, ids); @@ -1857,6 +1858,8 @@ int csoundCompileTreeInternal(CSOUND *csound, TREE *root, int async) { csoundSpinUnLock(&csound->alloc_spinlock); } } else { + /* now add the instruments with names, assigning them fake instr numbers */ + named_instr_assign_numbers(csound, engineState); /* first compilation */ insert_opcodes(csound, csound->opcodeInfo, engineState); ip = engineState->instxtanchor.nxtinstxt; diff --git a/Top/threadsafe.c b/Top/threadsafe.c index 07ce36c3f0e..8cf7335ea88 100644 --- a/Top/threadsafe.c +++ b/Top/threadsafe.c @@ -50,6 +50,8 @@ int csoundScoreEventAbsoluteInternal(CSOUND *csound, char type, void set_channel_data_ptr(CSOUND *csound, const char *name, void *ptr, int newSize); +void named_instr_assign_numbers(CSOUND *csound, ENGINE_STATE *engineState); + enum {INPUT_MESSAGE=1, READ_SCORE, SCORE_EVENT, SCORE_EVENT_ABS, TABLE_COPY_OUT, TABLE_COPY_IN, TABLE_SET, MERGE_STATE, KILL_INSTANCE}; @@ -222,6 +224,7 @@ void message_dequeue(CSOUND *csound) { sizeof(TYPE_TABLE *)); memcpy(&ids, msg->args + 2*ARG_ALIGN, sizeof(OPDS *)); + named_instr_assign_numbers(csound, e); merge_state(csound, e, t, ids); } break;