|
1 | 1 | //#define PER_INSTRUCTION_PROFILING |
2 | 2 |
|
3 | 3 | using UnityEngine; |
| 4 | +using UnityEngine.Serialization; |
4 | 5 | using System.Collections.Generic; |
5 | 6 | using System; |
6 | 7 | using System.Collections.Specialized; |
@@ -197,9 +198,20 @@ public object Interpret( CilboxProxy ths, object [] parametersIn ) |
197 | 198 | try |
198 | 199 | { |
199 | 200 | ret = InterpretInner( stackBuffer, parameters ).AsObject(); |
200 | | - } catch( Exception e ) |
| 201 | + } |
| 202 | + catch( Exception e ) |
201 | 203 | { |
202 | 204 | parentClass.box.InterpreterExit(); |
| 205 | + |
| 206 | + if (e is CilboxUnhandledInterpretedException uhe) |
| 207 | + { |
| 208 | + // strip the throwee just in case, and re-throw a normal runtime exception |
| 209 | + string exceptionTypeName = uhe.Throwee?.GetType().FullName ?? "null"; |
| 210 | + string reason = $"Exception of type {exceptionTypeName} was unhandled in interpreted code"; |
| 211 | + parentClass.box.DisableWithReason(reason); // CilboxUnhandledInterpretedException bypasses the box disable |
| 212 | + throw new CilboxInterpreterRuntimeException(reason, uhe.ClassName, uhe.MethodName, uhe.PC); |
| 213 | + } |
| 214 | + |
203 | 215 | Debug.Log( e.ToString() ); |
204 | 216 | throw; |
205 | 217 | } |
@@ -1541,10 +1553,7 @@ private StackElement InterpretInner( ArraySegment<StackElement> stackBufferIn, A |
1541 | 1553 | catch( Exception e ) |
1542 | 1554 | { |
1543 | 1555 | string fullError = $"Breakwarn: {e.ToString()} Class: {parentClass.className}, Function: {methodName}, Bytecode: {pc}"; |
1544 | | - Debug.LogError( fullError ); |
1545 | | - box.disabledReason = fullError; |
1546 | | - box.disabled = true; |
1547 | | - //box.InterpreterExit(); |
| 1556 | + box.DisableWithReason(fullError); |
1548 | 1557 |
|
1549 | 1558 | if (e is CilboxInterpreterRuntimeException) |
1550 | 1559 | { |
@@ -1936,7 +1945,15 @@ abstract public class Cilbox : MonoBehaviour |
1936 | 1945 | public String disabledReason = ""; |
1937 | 1946 | public bool disabled = false; |
1938 | 1947 |
|
1939 | | - public long timeoutLengthUs = 500000; // 500ms Can be changed by specific Cilbox application. |
| 1948 | + [SerializeField][FormerlySerializedAs("timeoutLengthUs")] private long desiredTimeoutLengthUs = 500000; // 500ms Can be changed by specific Cilbox instance. |
| 1949 | + public long timeoutLengthUs |
| 1950 | + { |
| 1951 | + get => desiredTimeoutLengthUs; |
| 1952 | + set => desiredTimeoutLengthUs = Math.Min(value, MaxTimeoutLengthUs); |
| 1953 | + } |
| 1954 | + |
| 1955 | + public virtual long MaxTimeoutLengthUs => 1000000; // 1 second. Can be overridden by specific Cilbox application. |
| 1956 | + |
1940 | 1957 | [HideInInspector] public uint interpreterAccountingDepth = 0; |
1941 | 1958 | [HideInInspector] public long interpreterAccountingDropDead = 0; |
1942 | 1959 | [HideInInspector] public long interpreterAccountingCumulitiveTicks = 0; |
@@ -1970,6 +1987,7 @@ public void BoxInitialize( bool bSimulate = false ) |
1970 | 1987 | if( initialized ) return; |
1971 | 1988 | initialized = true; |
1972 | 1989 | //Debug.Log( "Cilbox Initialize Metadata:" + assemblyData.Length ); |
| 1990 | + timeoutLengthUs = desiredTimeoutLengthUs; // make sure min is applied once. |
1973 | 1991 |
|
1974 | 1992 | Dictionary< String, Serializee > assemblyRoot = new Serializee( Convert.FromBase64String( assemblyData ), Serializee.ElementType.Map ).AsMap(); |
1975 | 1993 | Dictionary< String, Serializee > classData = assemblyRoot["classes"].AsMap(); |
@@ -2328,6 +2346,14 @@ void Update() |
2328 | 2346 | { |
2329 | 2347 | usSpentLastFrame = Interlocked.Exchange( ref interpreterAccountingCumulitiveTicks, 0 ) / interpreterTicksInUs; |
2330 | 2348 | } |
| 2349 | + |
| 2350 | + internal void DisableWithReason(string reason) |
| 2351 | + { |
| 2352 | + Debug.LogError( reason ); |
| 2353 | + this.disabledReason = reason; |
| 2354 | + this.disabled = true; |
| 2355 | + //this.InterpreterExit(); |
| 2356 | + } |
2331 | 2357 | } |
2332 | 2358 |
|
2333 | 2359 |
|
@@ -3025,10 +3051,11 @@ public enum ImportFunctionID |
3025 | 3051 | Update, |
3026 | 3052 | Start, |
3027 | 3053 | Awake, |
3028 | | - OnTriggerEnter, |
3029 | | - OnTriggerExit, |
3030 | 3054 | OnEnable, |
3031 | 3055 | OnDisable, |
| 3056 | + OnDestroy, |
| 3057 | + OnTriggerEnter, |
| 3058 | + OnTriggerExit, |
3032 | 3059 | OnCollisionEnter, |
3033 | 3060 | OnCollisionExit |
3034 | 3061 | } |
|
0 commit comments