Fix 'Open Scripts Externally' crashing studio.

Closes #369.
This commit is contained in:
Lucien Greathouse
2021-04-23 16:59:59 -04:00
parent f1c4102d7f
commit 0f7c9493d2
2 changed files with 17 additions and 4 deletions

View File

@@ -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

View File

@@ -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)