Skip to content

Commit

Permalink
fix: [workaround] Avoid crash when build app with batchmode on comman…
Browse files Browse the repository at this point in the history
…d-line (Unity-Technologies#742)

* fix

* workaround

* export YAMATO_JOB_ID

(cherry picked from commit cbdcf105ec97b79f2804e059c3fa164ec0d60cca)
  • Loading branch information
karasusan authored Aug 25, 2022
1 parent 0cfb5fa commit dbe91c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
3 changes: 2 additions & 1 deletion BuildScripts~/template/remote.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# python version is random on each VM
export PATH=$PATH:/usr/local/bin:/Users/bokken/Library/Python/3.7/bin:/Users/bokken/Library/Python/3.8/bin
export ARTIFACT_DIR=${PWD}/test-results
export YAMATO_JOB_ID=${YAMATO_JOB_ID}

# TEST_TARGET = `ios` or `macos`
# TEST_PLATFORM = `editmode` or `playmode` or `standalone`
Expand Down Expand Up @@ -93,4 +94,4 @@ else
fi

# return exit-code
exit $result
exit $result
15 changes: 8 additions & 7 deletions BuildScripts~/test_package_mac.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

#
# BOKKEN_DEVICE_IP:
# TEMPLATE_FILE:
# BOKKEN_DEVICE_IP:
# TEMPLATE_FILE:
# TEST_TARGET:
# TEST_PLATFORM:
# SCRIPTING_BACKEND:
Expand All @@ -12,7 +12,7 @@
# TEST_RESULT_DIR:
# EDITOR_VERSION:
#
#
#
# brew install gettext
#

Expand All @@ -33,7 +33,8 @@ envsubst ' \
$TEST_TARGET \
$TEST_PLATFORM \
$TEST_ARCHITECTURE \
$EDITOR_VERSION' \
$EDITOR_VERSION \
$YAMATO_JOB_ID' \
< ${TEMPLATE_FILE} \
> ~/remote.sh
chmod +x ~/remote.sh
Expand All @@ -49,7 +50,7 @@ then
fi

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

set +e

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

# return ssh commend results
# return ssh commend results
if [ $result -ne 0 ]; then
exit $result
fi
fi
31 changes: 26 additions & 5 deletions com.unity.renderstreaming/Runtime/Scripts/RenderStreaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,27 @@ public sealed class RenderStreaming : MonoBehaviour
[InitializeOnLoadMethod]
static void InitializeOnEditor()
{
/// todo(kazuki):: This is workaround.
/// When kicking the Unity Editor with batchmode flag on command line, The Unity Editor crashes
/// caused by not unloading WebRTC native plugin. By this workaround, Some static methods of this
/// package don't work correctly when batchmode. These static methods depend on WebRTC API,
/// therefore the package initialization must be completed just after launching Editor.
/// In the future, we will remove this workaround after improving the initialization of the
/// WebRTC package.
if(!IsYamato)
{
if (Application.isBatchMode)
return;
}
RenderStreamingInternal.DomainUnload();
RenderStreamingInternal.DomainLoad();
EditorApplication.quitting += RenderStreamingInternal.DomainUnload;
}

/// <summary>
/// Executed from the auto testing environment or not.
/// </summary>
static bool IsYamato => !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("YAMATO_JOB_ID"));
#else
[RuntimeInitializeOnLoadMethod]
static void InitializeOnRuntime()
Expand All @@ -59,19 +76,23 @@ static void InitializeOnRuntime()
}
#endif

static Type GetType(string typeName) {
static Type GetType(string typeName)
{
var type = Type.GetType(typeName);
if (type != null) return type;
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) {
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
{
type = assembly.GetType(typeName);
if (type != null) return type;
}
return null;
}

static ISignaling CreateSignaling(string type, string url, float interval, SynchronizationContext context) {
static ISignaling CreateSignaling(string type, string url, float interval, SynchronizationContext context)
{
Type _type = GetType(type);
if (_type == null) {
if (_type == null)
{
throw new ArgumentException($"Signaling type is undefined. {type}");
}
object[] args = { url, interval, context };
Expand All @@ -83,7 +104,7 @@ void Awake()
if (!runOnAwake || m_running)
return;

RTCConfiguration conf = new RTCConfiguration {iceServers = iceServers};
RTCConfiguration conf = new RTCConfiguration { iceServers = iceServers };
ISignaling signaling = CreateSignaling(
signalingType, urlSignaling, interval, SynchronizationContext.Current);
_Run(conf, signaling, handlers.ToArray());
Expand Down

0 comments on commit dbe91c7

Please sign in to comment.