From 0f7c9493d26a9d97e78a2ebebc0fb360262934f4 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 23 Apr 2021 16:59:59 -0400 Subject: [PATCH] Fix 'Open Scripts Externally' crashing studio. Closes #369. --- CHANGELOG.md | 4 ++++ plugin/src/ServeSession.lua | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 389fa319..0727425e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,13 @@ ## Unreleased Changes * Added "EXPERIMENTAL!" label to two-way sync toggle in Rojo's Roblox Studio plugin. +* Fixed "Open Scripts Externally" feature crashing Studio ([#369][issue-369]) + +[issue-369]: https://github.com/rojo-rbx/rojo/issues/369 ## [6.1.0][6.1.0] (April 12, 2021) * Updated dependencies, fixing OptionalCoordinateFrame-related issues. + * Added `--address` flag to `rojo serve` to allow for external connections. ([#403][pr-403]) [pr-403]: https://github.com/rojo-rbx/rojo/pull/403 diff --git a/plugin/src/ServeSession.lua b/plugin/src/ServeSession.lua index 9e06065f..70c7349d 100644 --- a/plugin/src/ServeSession.lua +++ b/plugin/src/ServeSession.lua @@ -1,4 +1,5 @@ local StudioService = game:GetService("StudioService") +local RunService = game:GetService("RunService") local Log = require(script.Parent.Parent.Log) local Fmt = require(script.Parent.Parent.Fmt) @@ -150,10 +151,18 @@ function ServeSession:__onActiveScriptChanged(activeScript) Log.debug("Trying to open script {} externally...", activeScript) - -- Force-close the script inside Studio - local existingParent = activeScript.Parent - activeScript.Parent = nil - activeScript.Parent = existingParent + -- Force-close the script inside Studio... with a small delay in the middle + -- to prevent Studio from crashing. + spawn(function() + local existingParent = activeScript.Parent + activeScript.Parent = nil + + for i = 1, 3 do + RunService.Heartbeat:Wait() + end + + activeScript.Parent = existingParent + end) -- Notify the Rojo server to open this script self.__apiContext:open(scriptId)