Skip to content

Commit dbe91c7

Browse files
authored
fix: [workaround] Avoid crash when build app with batchmode on command-line (#742)
* fix * workaround * export YAMATO_JOB_ID (cherry picked from commit cbdcf105ec97b79f2804e059c3fa164ec0d60cca)
1 parent 0cfb5fa commit dbe91c7

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

BuildScripts~/template/remote.sh.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# python version is random on each VM
55
export PATH=$PATH:/usr/local/bin:/Users/bokken/Library/Python/3.7/bin:/Users/bokken/Library/Python/3.8/bin
66
export ARTIFACT_DIR=${PWD}/test-results
7+
export YAMATO_JOB_ID=${YAMATO_JOB_ID}
78

89
# TEST_TARGET = `ios` or `macos`
910
# TEST_PLATFORM = `editmode` or `playmode` or `standalone`
@@ -93,4 +94,4 @@ else
9394
fi
9495

9596
# return exit-code
96-
exit $result
97+
exit $result

BuildScripts~/test_package_mac.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
#
4-
# BOKKEN_DEVICE_IP:
5-
# TEMPLATE_FILE:
4+
# BOKKEN_DEVICE_IP:
5+
# TEMPLATE_FILE:
66
# TEST_TARGET:
77
# TEST_PLATFORM:
88
# SCRIPTING_BACKEND:
@@ -12,7 +12,7 @@
1212
# TEST_RESULT_DIR:
1313
# EDITOR_VERSION:
1414
#
15-
#
15+
#
1616
# brew install gettext
1717
#
1818

@@ -33,7 +33,8 @@ envsubst ' \
3333
$TEST_TARGET \
3434
$TEST_PLATFORM \
3535
$TEST_ARCHITECTURE \
36-
$EDITOR_VERSION' \
36+
$EDITOR_VERSION \
37+
$YAMATO_JOB_ID' \
3738
< ${TEMPLATE_FILE} \
3839
> ~/remote.sh
3940
chmod +x ~/remote.sh
@@ -49,7 +50,7 @@ then
4950
fi
5051

5152
# copy package to remote machine
52-
scp -i ${IDENTITY} -r ${YAMATO_SOURCE_DIR} bokken@${BOKKEN_DEVICE_IP}:~/${PACKAGE_DIR}
53+
scp -i ${IDENTITY} -r ${YAMATO_SOURCE_DIR} bokken@${BOKKEN_DEVICE_IP}:~/${PACKAGE_DIR}
5354

5455
set +e
5556

@@ -63,7 +64,7 @@ set -e
6364
mkdir -p ${TEST_RESULT_DIR}
6465
scp -i ${IDENTITY} -r bokken@${BOKKEN_DEVICE_IP}:~/test-results ${TEST_RESULT_DIR}
6566

66-
# return ssh commend results
67+
# return ssh commend results
6768
if [ $result -ne 0 ]; then
6869
exit $result
69-
fi
70+
fi

com.unity.renderstreaming/Runtime/Scripts/RenderStreaming.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,27 @@ public sealed class RenderStreaming : MonoBehaviour
4545
[InitializeOnLoadMethod]
4646
static void InitializeOnEditor()
4747
{
48+
/// todo(kazuki):: This is workaround.
49+
/// When kicking the Unity Editor with batchmode flag on command line, The Unity Editor crashes
50+
/// caused by not unloading WebRTC native plugin. By this workaround, Some static methods of this
51+
/// package don't work correctly when batchmode. These static methods depend on WebRTC API,
52+
/// therefore the package initialization must be completed just after launching Editor.
53+
/// In the future, we will remove this workaround after improving the initialization of the
54+
/// WebRTC package.
55+
if(!IsYamato)
56+
{
57+
if (Application.isBatchMode)
58+
return;
59+
}
4860
RenderStreamingInternal.DomainUnload();
4961
RenderStreamingInternal.DomainLoad();
5062
EditorApplication.quitting += RenderStreamingInternal.DomainUnload;
5163
}
64+
65+
/// <summary>
66+
/// Executed from the auto testing environment or not.
67+
/// </summary>
68+
static bool IsYamato => !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("YAMATO_JOB_ID"));
5269
#else
5370
[RuntimeInitializeOnLoadMethod]
5471
static void InitializeOnRuntime()
@@ -59,19 +76,23 @@ static void InitializeOnRuntime()
5976
}
6077
#endif
6178

62-
static Type GetType(string typeName) {
79+
static Type GetType(string typeName)
80+
{
6381
var type = Type.GetType(typeName);
6482
if (type != null) return type;
65-
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) {
83+
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
84+
{
6685
type = assembly.GetType(typeName);
6786
if (type != null) return type;
6887
}
6988
return null;
7089
}
7190

72-
static ISignaling CreateSignaling(string type, string url, float interval, SynchronizationContext context) {
91+
static ISignaling CreateSignaling(string type, string url, float interval, SynchronizationContext context)
92+
{
7393
Type _type = GetType(type);
74-
if (_type == null) {
94+
if (_type == null)
95+
{
7596
throw new ArgumentException($"Signaling type is undefined. {type}");
7697
}
7798
object[] args = { url, interval, context };
@@ -83,7 +104,7 @@ void Awake()
83104
if (!runOnAwake || m_running)
84105
return;
85106

86-
RTCConfiguration conf = new RTCConfiguration {iceServers = iceServers};
107+
RTCConfiguration conf = new RTCConfiguration { iceServers = iceServers };
87108
ISignaling signaling = CreateSignaling(
88109
signalingType, urlSignaling, interval, SynchronizationContext.Current);
89110
_Run(conf, signaling, handlers.ToArray());

0 commit comments

Comments
 (0)