fix runtime debug assertion code: this assertion will only be called if the debug mode is enabled
This commit is contained in:
Родитель
9f84c28afe
Коммит
5547917c8a
|
@ -211,8 +211,6 @@ UIWidgets也支持Gif!
|
|||
|
||||
在编辑器菜单栏选择```UIWidgets->EnableDebug```
|
||||
|
||||
如果想在runtime开启debug模式,请在项目代码中设置```UIWidgetsGlobalConfiguration.EnableDebugAtRuntime = true```。在默认情况下debug模式为关闭状态。
|
||||
|
||||
## 使用Window Scope保护外部调用
|
||||
如果您在调试时遇到 `AssertionError: Window.instance is null` 或者在调用 `Window.instance` 时得到空指针, 那么您需要
|
||||
使用以下方式来保护您的调用,使之可以在正确的Isolate上执行回调逻辑:
|
||||
|
|
|
@ -220,9 +220,7 @@ Long time garbage collection may cause App to stuck frequently. You can enable i
|
|||
|
||||
## Debug UIWidgets Application
|
||||
|
||||
In Unity editor, you can switch debug/release mode by “UIWidgets->EnableDebug”.
|
||||
|
||||
You can also enable debug mode in runtime by setting ```UIWidgetsGlobalConfiguration.EnableDebugAtRuntime = true``` in your project. Note that this value is set to false by default.
|
||||
You can switch debug/release mode by “UIWidgets->EnableDebug” in the Unity Editor.
|
||||
|
||||
## Using Window Scope
|
||||
If you see the error `AssertionError: Window.instance is null` or null pointer error of `Window.instance`,
|
||||
|
|
|
@ -5,8 +5,5 @@ namespace Unity.UIWidgets.engine {
|
|||
|
||||
//disable incremental gc by default
|
||||
public static bool EnableIncrementalGC = false;
|
||||
|
||||
//disable debug at runtime by default
|
||||
public static bool EnableDebugAtRuntime = false;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Unity.UIWidgets.engine;
|
||||
|
@ -53,6 +54,8 @@ namespace Unity.UIWidgets.foundation {
|
|||
|
||||
public static bool debugPrintMouseHoverEvents = false;
|
||||
|
||||
public const string debugScriptingDefineSymbol = "DebugUIWidgets";
|
||||
|
||||
public static HSVColor debugCurrentRepaintColor =
|
||||
HSVColor.fromAHSV(0.4f, 60.0f, 1.0f, 1.0f);
|
||||
|
||||
|
@ -62,13 +65,14 @@ namespace Unity.UIWidgets.foundation {
|
|||
Debug.LogException(new AssertionError(message: message, innerException: ex));
|
||||
}
|
||||
|
||||
[Conditional("UNITY_ASSERTIONS")]
|
||||
[Conditional(debugScriptingDefineSymbol)]
|
||||
public static void assert(Func<bool> result, Func<string> message = null) {
|
||||
if ( enableDebug && !result() ) {
|
||||
throw new AssertionError(message != null ? message() : "");
|
||||
}
|
||||
}
|
||||
[Conditional("UNITY_ASSERTIONS")]
|
||||
|
||||
[Conditional(debugScriptingDefineSymbol)]
|
||||
public static void assert(bool result, Func<string> message = null) {
|
||||
if ( enableDebug && !result ) {
|
||||
throw new AssertionError(message != null ? message() : "");
|
||||
|
@ -77,6 +81,24 @@ namespace Unity.UIWidgets.foundation {
|
|||
|
||||
#if UNITY_EDITOR
|
||||
static bool? _enableDebug = null;
|
||||
|
||||
private static void setRuntimeSymbolsForTarget(BuildTargetGroup targetGroup, bool enabled) {
|
||||
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
var defineList = defines.Split(';');
|
||||
var newDefineList = new List<string>();
|
||||
foreach (var define in defineList) {
|
||||
if (define != debugScriptingDefineSymbol) {
|
||||
newDefineList.Add(define);
|
||||
}
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
newDefineList.Add(debugScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, String.Join(";", newDefineList));
|
||||
}
|
||||
|
||||
public static bool enableDebug {
|
||||
get {
|
||||
if (_enableDebug == null) {
|
||||
|
@ -90,10 +112,14 @@ namespace Unity.UIWidgets.foundation {
|
|||
}
|
||||
_enableDebug = value;
|
||||
EditorPrefs.SetInt("UIWidgetsDebug",value ? 1 : 0);
|
||||
setRuntimeSymbolsForTarget(BuildTargetGroup.Android, value);
|
||||
setRuntimeSymbolsForTarget(BuildTargetGroup.iOS, value);
|
||||
setRuntimeSymbolsForTarget(BuildTargetGroup.Standalone, value);
|
||||
}
|
||||
}
|
||||
#else
|
||||
public static bool enableDebug => UIWidgetsGlobalConfiguration.EnableDebugAtRuntime;
|
||||
//In runtime, we use the Conditional decorator "debugScriptingDefineSymbol" instead of this to enable/disable debug mode
|
||||
public static bool enableDebug => true;
|
||||
#endif
|
||||
|
||||
public static void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче