mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-18 03:36:22 +02:00
Merge pull request #5811 from ZappoMan/scriptEngineCleanup
Rework the ScriptEngine shutdown process, Fix crash in AC Scripts
This commit is contained in:
commit
4c0a21f3d2
2 changed files with 8 additions and 9 deletions
|
@ -41,9 +41,6 @@ Agent::Agent(NLPacket& packet) :
|
|||
DEFAULT_WINDOW_STARVE_THRESHOLD, DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES,
|
||||
DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false))
|
||||
{
|
||||
// be the parent of the script engine so it gets moved when we do
|
||||
_scriptEngine->setParent(this);
|
||||
|
||||
DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
|
||||
|
||||
DependencyManager::set<ResourceCacheSharedItems>();
|
||||
|
@ -157,6 +154,7 @@ void Agent::run() {
|
|||
qDebug() << "Downloaded script:" << scriptContents;
|
||||
|
||||
_scriptEngine = new ScriptEngine(scriptContents, _payload);
|
||||
_scriptEngine->setParent(this); // be the parent of the script engine so it gets moved when we do
|
||||
|
||||
// setup an Avatar for the script to use
|
||||
ScriptableAvatar scriptedAvatar(_scriptEngine);
|
||||
|
@ -255,7 +253,6 @@ void Agent::sendAvatarBillboardPacket() {
|
|||
|
||||
|
||||
void Agent::processAgentAvatarAndAudio(float deltaTime) {
|
||||
qDebug() << "processAgentAvatarAndAudio()";
|
||||
if (!_scriptEngine->isFinished() && _isAvatar && _avatarData) {
|
||||
|
||||
const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * AudioConstants::SAMPLE_RATE)
|
||||
|
|
|
@ -118,19 +118,21 @@ ScriptEngine::~ScriptEngine() {
|
|||
}
|
||||
|
||||
void ScriptEngine::runInThread() {
|
||||
QThread* workerThread = new QThread(this);
|
||||
QThread* workerThread = new QThread(); // thread is not owned, so we need to manage the delete
|
||||
QString scriptEngineName = QString("Script Thread:") + getFilename();
|
||||
workerThread->setObjectName(scriptEngineName);
|
||||
|
||||
// when the worker thread is started, call our engine's run..
|
||||
connect(workerThread, &QThread::started, this, &ScriptEngine::run);
|
||||
|
||||
// when the thread is terminated, add both scriptEngine and thread to the deleteLater queue
|
||||
connect(this, &ScriptEngine::doneRunning, this, &ScriptEngine::deleteLater);
|
||||
// tell the thread to stop when the script engine is done
|
||||
connect(this, &ScriptEngine::doneRunning, workerThread, &QThread::quit);
|
||||
|
||||
// when the thread is finished, add thread to the deleteLater queue
|
||||
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
|
||||
|
||||
// tell the thread to stop when the script engine is done
|
||||
connect(this, &ScriptEngine::destroyed, workerThread, &QThread::quit);
|
||||
// when the thread is finished, add scriptEngine to the deleteLater queue
|
||||
connect(workerThread, &QThread::finished, this, &ScriptEngine::deleteLater);
|
||||
|
||||
moveToThread(workerThread);
|
||||
|
||||
|
|
Loading…
Reference in a new issue