Skip to content

Commit

Permalink
HACK: Fixed/worked around problem where temp files would be locked an…
Browse files Browse the repository at this point in the history
…d inaccessible when changing TextScenes. This problem surfaces mostly on windows. See FIXME in TextSceneMonitor.cs
  • Loading branch information
Trond Abusdal committed Mar 24, 2010
1 parent e87dbf4 commit b4e9aa9
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 17 deletions.
126 changes: 126 additions & 0 deletions Assets/Scenes/otherscenedemo.txt
@@ -0,0 +1,126 @@
gameobject Cube
tag Untagged layer 0
0.00000 -2.48280 0.00000
0.00000 0.00000 0.00000 1.00000
1.00000 1.00000 1.00000
children 0
components 3
UnityEngine.MeshFilter 1
property sharedMesh builtinmesh UnityEngine.Mesh = Cube
UnityEngine.BoxCollider 4
property center primitive UnityEngine.Vector3 = (0.0, 0.0, 0.0)
property size primitive UnityEngine.Vector3 = (1.0, 1.0, 1.0)
property extents primitive UnityEngine.Vector3 = (0.5, 0.5, 0.5)
property isTrigger primitive System.Boolean = False
UnityEngine.MeshRenderer 5
property castShadows primitive System.Boolean = True
property receiveShadows primitive System.Boolean = True
property sharedMaterials array UnityEngine.Material[] = 1
builtinmaterial UnityEngine.Material = Default-Diffuse
property lightmapIndex primitive System.Int32 = -1
property lightmapTilingOffset primitive UnityEngine.Vector4 = (1.0, 1.0, 0.0, 0.0)

gameobject Cube
tag Untagged layer 0
3.00000 -2.48280 2.00000
0.00000 0.00000 0.00000 1.00000
1.00000 1.00000 1.00000
children 1
gameobject Cube
tag Untagged layer 0
-10.00000 6.00000 0.00000
0.00000 0.00000 0.00000 1.00000
1.00000 1.00000 1.00000
children 0
components 3
UnityEngine.MeshFilter 1
property sharedMesh builtinmesh UnityEngine.Mesh = Cube
UnityEngine.BoxCollider 4
property center primitive UnityEngine.Vector3 = (0.0, 0.0, 0.0)
property size primitive UnityEngine.Vector3 = (1.0, 1.0, 1.0)
property extents primitive UnityEngine.Vector3 = (0.5, 0.5, 0.5)
property isTrigger primitive System.Boolean = False
UnityEngine.MeshRenderer 5
property castShadows primitive System.Boolean = True
property receiveShadows primitive System.Boolean = True
property sharedMaterials array UnityEngine.Material[] = 1
asset UnityEngine.Material = Assets/Materials/CustomMaterial.mat, CustomMaterial, e9b851d350fc14be09ce3ba99babfe07
property lightmapIndex primitive System.Int32 = -1
property lightmapTilingOffset primitive UnityEngine.Vector4 = (1.0, 1.0, 0.0, 0.0)
components 3
UnityEngine.MeshFilter 1
property sharedMesh builtinmesh UnityEngine.Mesh = Cube
UnityEngine.BoxCollider 4
property center primitive UnityEngine.Vector3 = (0.0, 0.0, 0.0)
property size primitive UnityEngine.Vector3 = (1.0, 1.0, 1.0)
property extents primitive UnityEngine.Vector3 = (0.5, 0.5, 0.5)
property isTrigger primitive System.Boolean = False
UnityEngine.MeshRenderer 5
property castShadows primitive System.Boolean = True
property receiveShadows primitive System.Boolean = True
property sharedMaterials array UnityEngine.Material[] = 1
builtinmaterial UnityEngine.Material = Default-Diffuse
property lightmapIndex primitive System.Int32 = -1
property lightmapTilingOffset primitive UnityEngine.Vector4 = (1.0, 1.0, 0.0, 0.0)

gameobject Directional light
tag Untagged layer 0
740.81120 66.71914 1054.85100
0.37889 0.00000 0.00000 0.92544
1.00000 1.00000 1.00000
children 0
components 1
UnityEngine.Light 12
property type primitive UnityEngine.LightType = Directional
property color primitive UnityEngine.Color = (1.000, 1.000, 1.000, 1.000)
property intensity primitive System.Single = 0.5
property shadows primitive UnityEngine.LightShadows = None
property shadowStrength primitive System.Single = 0.8
property shadowConstantBias primitive System.Single = 0.07
property shadowObjectSizeBias primitive System.Single = 0.01
property attenuate primitive System.Boolean = True
property range primitive System.Single = 10
property spotAngle primitive System.Single = 30
property renderMode primitive UnityEngine.LightRenderMode = Auto
property cullingMask primitive System.Int32 = -1

gameobject Links
tag Untagged layer 0
8.54124 9.88922 -6.45947
0.00000 0.00000 0.00000 1.00000
1.00000 1.00000 1.00000
children 0
components 1
TextSceneLinkTest 4
field materialList array UnityEngine.Material[] = 0
field prefabLink asset UnityEngine.GameObject = Assets/Prefabs/Capsules.prefab, Capsules, f0529f741bc2540eea3ec100e446c639
field colliderLink scenelink UnityEngine.BoxCollider = /Cube/Cube
field nextScene primitive System.String = scenedemo

gameobject Main Camera
tag MainCamera layer 0
0.00000 1.00000 -10.00000
0.00000 0.00000 0.00000 1.00000
1.00000 1.00000 1.00000
children 0
components 3
UnityEngine.Camera 15
property fov primitive System.Single = 60
property near primitive System.Single = 0.3
property far primitive System.Single = 1000
property fieldOfView primitive System.Single = 60
property nearClipPlane primitive System.Single = 0.3
property farClipPlane primitive System.Single = 1000
property orthographicSize primitive System.Single = 100
property orthographic primitive System.Boolean = False
property isOrthoGraphic primitive System.Boolean = False
property depth primitive System.Single = -1
property cullingMask primitive System.Int32 = -1
property backgroundColor primitive UnityEngine.Color = (0.192, 0.302, 0.475, 0.020)
property rect primitive UnityEngine.Rect = (0.00, 0.00, 1.00, 1.00)
property clearFlags primitive UnityEngine.CameraClearFlags = Skybox
property depthTextureMode primitive UnityEngine.DepthTextureMode = None
UnityEngine.GUILayer 0
UnityEngine.AudioListener 1
property velocityUpdateMode primitive UnityEngine.AudioVelocityUpdateMode = Dynamic

2 changes: 2 additions & 0 deletions Assets/Scenes/otherscenedemo.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/Scenes/scenedemo.txt
Expand Up @@ -97,12 +97,13 @@ tag Untagged layer 0
1.00000 1.00000 1.00000
children 0
components 1
TextSceneLinkTest 5
TextSceneLinkTest 6
field materialList array UnityEngine.Material[] = 0
field goLink scenelink UnityEngine.GameObject = /spheres/UniqueName
field transformLink scenelink UnityEngine.Transform = /Capsule/Capsule
field prefabLink asset UnityEngine.GameObject = Assets/Prefabs/Capsules.prefab, Capsules, f0529f741bc2540eea3ec100e446c639
field colliderLink scenelink UnityEngine.BoxCollider = /Cube/Cube
field nextScene primitive System.String = otherscenedemo

gameobject Main Camera
tag MainCamera layer 0
Expand Down
32 changes: 32 additions & 0 deletions Assets/Scripts/Editor/TextScene/TextSceneMonitor.cs
Expand Up @@ -220,6 +220,38 @@ private void Update()

if (saveAndReload.Length > 0 && saveAndReloadTimer <= 0)
{
///FIXME: Unity sometimes puts a lock on the scenes we try to save, this is a CRUEL way to
///get around it. This problem seems to be a lot more frequent on Windows than on MacOSX.
///
///Repro-steps: *Comment out the try/catch
/// *Clean out tempscenes-folder.
/// *Open up a scene (LEVEL1) from build settings, hit play
/// *Answer "yes" to the dialog box whining about invalid build settings
/// *Hit play again, once it has completed doing its stuff.
/// *While playing, do something to make the game
/// change to another level (LEVEL2).
/// *Stop playing, you should now be back in the level where you
/// hit play from.
/// *Try to switch to the level you switched to in-game (LEVEL2).
/// *You should, after the progress bar has completed, be prompted
/// with an error saying Unity could not move file from Temp/Tempfile
///
try
{
FileStream f = File.OpenWrite(saveAndReload);
f.Close();
}
catch
{
Debug.LogWarning("HACK: Getting around 'access denied' on temp files!");

//HACK: This seems to make Unity release the file so we can try to save it in a new go.
EditorApplication.OpenScene(saveAndReload);

TextSceneDeserializer.Load(EditorHelper.GetProjectFolder() + TextScene.TempToTextSceneFile(EditorApplication.currentScene), saveAndReloadCallback);
return;
}

EditorApplication.SaveScene(saveAndReload);
EditorApplication.OpenScene(saveAndReload);

Expand Down
44 changes: 28 additions & 16 deletions Assets/Scripts/TextScene/TextSceneLinkTest.cs
@@ -1,16 +1,28 @@
///
/// Copyright (c) 2010 TerraVision AS
/// See LICENSE file for licensing details
///

using UnityEngine;

class TextSceneLinkTest : MonoBehaviour
{
public Material[] materialList;
public GameObject goLink;
public Transform transformLink;
public GameObject prefabLink;
public BoxCollider colliderLink;
}

///
/// Copyright (c) 2010 TerraVision AS
/// See LICENSE file for licensing details
///

using UnityEngine;

class TextSceneLinkTest : MonoBehaviour
{
public Material[] materialList;
public GameObject goLink;
public Transform transformLink;
public GameObject prefabLink;
public BoxCollider colliderLink;

public string nextScene;

protected void OnGUI()
{
if (GUI.Button(new Rect(20.0f, 20.0f, 100.0f, 20.0f), "Change scene"))
{
if (nextScene != null && nextScene.Length > 0)
Application.LoadLevel(nextScene);
else
Application.LoadLevel(Application.loadedLevelName);
}
}
}
1 change: 1 addition & 0 deletions Library/TextSceneBuildSettings.txt
@@ -1 +1,2 @@
scene Assets/Scenes/scenedemo.txt
scene Assets/Scenes/otherscenedemo.txt

0 comments on commit b4e9aa9

Please sign in to comment.