Browse Source

Script subsystem prints the stack strace automatically on exception.

Wei Tjong Yao 12 years ago
parent
commit
de9b19d6d4

+ 6 - 10
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -69,7 +69,6 @@ void CreateAttributeInspectorWindow()
     attributeInspectorWindow.SetPosition(ui.root.width - 20 - attributeInspectorWindow.width, 40);
     attributeInspectorWindow.SetPosition(ui.root.width - 20 - attributeInspectorWindow.width, 40);
     attributeInspectorWindow.opacity = uiMaxOpacity;
     attributeInspectorWindow.opacity = uiMaxOpacity;
     attributeInspectorWindow.BringToFront();
     attributeInspectorWindow.BringToFront();
-    UpdateAttributeInspector();
 
 
     SubscribeToEvent(attributeInspectorWindow.GetChild("CloseButton", true), "Released", "HideAttributeInspectorWindow");
     SubscribeToEvent(attributeInspectorWindow.GetChild("CloseButton", true), "Released", "HideAttributeInspectorWindow");
     SubscribeToEvent(attributeInspectorWindow, "LayoutUpdated", "HandleWindowLayoutUpdated");
     SubscribeToEvent(attributeInspectorWindow, "LayoutUpdated", "HandleWindowLayoutUpdated");
@@ -117,14 +116,11 @@ void UpdateAttributeInspector(bool fullUpdate = true)
 {
 {
     attributesDirty = false;
     attributesDirty = false;
 
 
+    // If full update delete all containers and added them back as necessary
     if (fullUpdate)
     if (fullUpdate)
-    {
         DeleteAllContainers();
         DeleteAllContainers();
-        AddNodeContainer();
-        AddComponentContainer();
-    }
 
 
-    Text@ nodeTitle = nodeContainer.GetChild("NodeTitle");
+    Text@ nodeTitle = nodeContainer.GetChild("TitleText");
     String nodeType;
     String nodeType;
     if (editNodes.length == 0)
     if (editNodes.length == 0)
         nodeTitle.text = "No node";
         nodeTitle.text = "No node";
@@ -159,7 +155,7 @@ void UpdateAttributeInspector(bool fullUpdate = true)
 
 
     if (editComponents.empty)
     if (editComponents.empty)
     {
     {
-        Text@ componentTitle = GetComponentContainer(0).GetChild("ComponentTitle");
+        Text@ componentTitle = GetComponentContainer(0).GetChild("TitleText");
         if (selectedComponents.length <= 1)
         if (selectedComponents.length <= 1)
             componentTitle.text = "No component";
             componentTitle.text = "No component";
         else
         else
@@ -180,7 +176,7 @@ void UpdateAttributeInspector(bool fullUpdate = true)
             if (j >= parentContainer.numChildren - componentContainerStartIndex)
             if (j >= parentContainer.numChildren - componentContainerStartIndex)
                 AddComponentContainer();
                 AddComponentContainer();
 
 
-            Text@ componentTitle = GetComponentContainer(j).GetChild("ComponentTitle");
+            Text@ componentTitle = GetComponentContainer(j).GetChild("TitleText");
             componentTitle.text = GetComponentTitle(editComponents[j * numEditableComponents]) + multiplierText;
             componentTitle.text = GetComponentTitle(editComponents[j * numEditableComponents]) + multiplierText;
             IconizeUIElement(componentTitle, editComponents[j * numEditableComponents].typeName);
             IconizeUIElement(componentTitle, editComponents[j * numEditableComponents].typeName);
             SetIconEnabledColor(componentTitle, editComponents[j * numEditableComponents].enabledEffective);
             SetIconEnabledColor(componentTitle, editComponents[j * numEditableComponents].enabledEffective);
@@ -203,7 +199,7 @@ void UpdateNodeAttributes()
 
 
 void UpdateAttributeInspectorIcons()
 void UpdateAttributeInspectorIcons()
 {
 {
-    Text@ nodeTitle = attributeInspectorWindow.GetChild("NodeTitle", true);
+    Text@ nodeTitle = nodeContainer.GetChild("TitleText");
     if (editNode !is null)
     if (editNode !is null)
         SetIconEnabledColor(nodeTitle, editNode.enabled);
         SetIconEnabledColor(nodeTitle, editNode.enabled);
     else if (editNodes.length > 0)
     else if (editNodes.length > 0)
@@ -228,7 +224,7 @@ void UpdateAttributeInspectorIcons()
 
 
         for (uint j = 0; j < numEditableComponentsPerNode; ++j)
         for (uint j = 0; j < numEditableComponentsPerNode; ++j)
         {
         {
-            Text@ componentTitle = GetComponentContainer(j).GetChild("ComponentTitle");
+            Text@ componentTitle = GetComponentContainer(j).GetChild("TitleText");
 
 
             bool enabledEffective = editComponents[j * numEditableComponents].enabledEffective;
             bool enabledEffective = editComponents[j * numEditableComponents].enabledEffective;
             bool hasSameEnabledState = true;
             bool hasSameEnabledState = true;

+ 2 - 2
Bin/Data/Scripts/Editor/EditorUIElement.as

@@ -6,8 +6,8 @@ XMLFile@ uiElementDefaultStyle;
 String childElementFileName;
 String childElementFileName;
 
 
 UIElement@ editUIElement;
 UIElement@ editUIElement;
-Array<UIElement@> selectedUIElements;
-Array<UIElement@> editUIElements;
+Array<Serializable@> selectedUIElements;
+Array<Serializable@> editUIElements;
 
 
 bool suppressUIElementChanges = false;
 bool suppressUIElementChanges = false;
 
 

+ 1 - 1
Bin/Data/UI/EditorComponent.xml

@@ -5,7 +5,7 @@
         <attribute name="Layout Spacing" value="4" />
         <attribute name="Layout Spacing" value="4" />
         <element type="BorderImage" style="EditorDivider" />
         <element type="BorderImage" style="EditorDivider" />
         <element type="Text">
         <element type="Text">
-            <attribute name="Name" value="ComponentTitle" />
+            <attribute name="Name" value="TitleText" />
             <attribute name="Min Size" value="0 17" />
             <attribute name="Min Size" value="0 17" />
             <attribute name="Max Size" value="2147483647 17" />
             <attribute name="Max Size" value="2147483647 17" />
         </element>
         </element>

+ 3 - 2
Bin/Data/UI/EditorNode.xml

@@ -1,11 +1,12 @@
+<!-- This container can be used for both Node and UIElement -->
 <element>
 <element>
     <element>
     <element>
-        <attribute name="Name" value="NodeContainer" />
+        <attribute name="Name" value="Node Container" />
         <attribute name="Layout Mode" value="Vertical" />
         <attribute name="Layout Mode" value="Vertical" />
         <attribute name="Layout Spacing" value="4" />
         <attribute name="Layout Spacing" value="4" />
         <element type="BorderImage" style="EditorDivider" />
         <element type="BorderImage" style="EditorDivider" />
         <element type="Text">
         <element type="Text">
-            <attribute name="Name" value="NodeTitle" />
+            <attribute name="Name" value="TitleText" />
             <attribute name="Min Size" value="0 17" />
             <attribute name="Min Size" value="0 17" />
             <attribute name="Max Size" value="2147483647 17" />
             <attribute name="Max Size" value="2147483647 17" />
         </element>
         </element>

+ 6 - 4
Bin/Data/UI/EditorSceneWindow.xml

@@ -47,10 +47,12 @@
         </element>
         </element>
         <element type="CheckBox">
         <element type="CheckBox">
             <attribute name="Name" value="AllCheckBox" />
             <attribute name="Name" value="AllCheckBox" />
-            <attribute name="Min Size" value="15 15" />
-            <attribute name="Max Size" value="15 15" />
-            <attribute name="Layout Mode" value="Horizontal" />
-            <attribute name="Layout Border" value="20 0 0 0" />
+            <attribute name="Min Size" value="45 15" />
+            <attribute name="Max Size" value="45 15" />
+            <attribute name="Indent Spacing" value="30" />
+            <attribute name="Indent" value="1" />
+            <attribute name="Layout Mode" value="Vertical" />
+            <attribute name="Layout Border" value="5 1 1 1" />
             <element type="Text">
             <element type="Text">
                 <attribute name="Text" value="All" />
                 <attribute name="Text" value="All" />
             </element>
             </element>

+ 1 - 13
Engine/Engine/IOAPI.cpp

@@ -26,7 +26,6 @@
 #include "Log.h"
 #include "Log.h"
 #include "PackageFile.h"
 #include "PackageFile.h"
 #include "ProcessUtils.h"
 #include "ProcessUtils.h"
-#include "StringUtils.h"
 #include "VectorBuffer.h"
 #include "VectorBuffer.h"
 
 
 namespace Urho3D
 namespace Urho3D
@@ -81,18 +80,7 @@ static void PrintCallStack(bool error)
 {
 {
     asIScriptContext* context = asGetActiveContext();
     asIScriptContext* context = asGetActiveContext();
     if (context)
     if (context)
-    {
-        // Show the call stack
-        for (asUINT i = 0; i < context->GetCallstackSize(); i++)
-        {
-            asIScriptFunction* func;
-            const char* scriptSection;
-            int line, column;
-            func = context->GetFunction(i);
-            line = context->GetLineNumber(i, &column, &scriptSection);
-            Log::WriteRaw(ToString("%s:%s:%d,%d\n", scriptSection, func->GetDeclaration(), line, column), error);
-        }
-    }
+        Log::WriteRaw(Script::GetCallStack(context), error);
 }
 }
 
 
 static void LogWrite(const String& str, bool error, Log* ptr)
 static void LogWrite(const String& str, bool error, Log* ptr)

+ 20 - 1
Engine/Script/Script.cpp

@@ -395,7 +395,8 @@ void Script::ExceptionCallback(asIScriptContext* context)
 {
 {
     asIScriptFunction *function = context->GetExceptionFunction();
     asIScriptFunction *function = context->GetExceptionFunction();
     String message = "Exception '" + String(context->GetExceptionString()) + "' in '" +
     String message = "Exception '" + String(context->GetExceptionString()) + "' in '" +
-        String(function->GetDeclaration()) + "'";
+        String(function->GetDeclaration()) + "'\n";
+    message += GetCallStack(context);
     
     
     asSMessageInfo msg;
     asSMessageInfo msg;
     msg.row = context->GetExceptionLineNumber(&msg.col, &msg.section);
     msg.row = context->GetExceptionLineNumber(&msg.col, &msg.section);
@@ -405,6 +406,24 @@ void Script::ExceptionCallback(asIScriptContext* context)
     MessageCallback(&msg);
     MessageCallback(&msg);
 }
 }
 
 
+String Script::GetCallStack(asIScriptContext* context)
+{
+    String str("AngelScript callstack:\n");
+
+    // Append the call stack
+    for (asUINT i = 0; i < context->GetCallstackSize(); i++)
+    {
+        asIScriptFunction* func;
+        const char* scriptSection;
+        int line, column;
+        func = context->GetFunction(i);
+        line = context->GetLineNumber(i, &column, &scriptSection);
+        str.AppendWithFormat("\t%s:%s:%d,%d\n", scriptSection, func->GetDeclaration(), line, column);
+    }
+
+    return str;
+}
+
 ScriptFile* Script::GetDefaultScriptFile() const
 ScriptFile* Script::GetDefaultScriptFile() const
 {
 {
     return defaultScriptFile_;
     return defaultScriptFile_;

+ 2 - 0
Engine/Script/Script.h

@@ -74,6 +74,8 @@ public:
     void MessageCallback(const asSMessageInfo* msg);
     void MessageCallback(const asSMessageInfo* msg);
     /// Handle a script exception.
     /// Handle a script exception.
     void ExceptionCallback(asIScriptContext* context);
     void ExceptionCallback(asIScriptContext* context);
+    /// Get call stack.
+    static String GetCallStack(asIScriptContext* context);
     
     
     /// Return the AngelScript engine.
     /// Return the AngelScript engine.
     asIScriptEngine* GetScriptEngine() const { return scriptEngine_; }
     asIScriptEngine* GetScriptEngine() const { return scriptEngine_; }