--- linuxsampler/trunk/src/engines/EngineBase.h 2017/05/24 20:05:38 3205 +++ linuxsampler/trunk/src/engines/EngineBase.h 2017/05/26 18:30:42 3221 @@ -984,6 +984,10 @@ // script event object RTList::Iterator itScriptEvent = pChannel->pScript->pEvents->allocAppend(); + // if event handler uses polyphonic variables, reset them + // to zero values before starting to execute the handler + if (pEventHandler->isPolyphonic()) + itScriptEvent->execCtx->resetPolyphonicData(); ProcessScriptEvent( pChannel, itEvent, pEventHandler, itScriptEvent ); @@ -1300,9 +1304,20 @@ itScriptEvent->ignoreAllWaitCalls = false; itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT; - /*VMExecStatus_t res = */ pScriptVM->exec( - pEngineChannel->pScript->parserContext, &*itScriptEvent - ); + VMExecStatus_t res; + size_t instructionsCount = 0; + const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction) + bool bWarningShown = false; + do { + res = pScriptVM->exec( + pEngineChannel->pScript->parserContext, &*itScriptEvent + ); + instructionsCount += itScriptEvent->execCtx->instructionsPerformed(); + if (instructionsCount > maxInstructions && !bWarningShown) { + bWarningShown = true; + dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n")); + } + } while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR)); pEngineChannel->pScript->pEvents->free(itScriptEvent); }