From d2a1202803811e204793da02b21e711b359eb9a1 Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Sat, 11 Apr 2026 12:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E5=9B=BE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/blueprint/exec.go | 4 +++- util/blueprint/graph.go | 43 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/util/blueprint/exec.go b/util/blueprint/exec.go index 5572224..3d386a5 100644 --- a/util/blueprint/exec.go +++ b/util/blueprint/exec.go @@ -167,6 +167,7 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) { for _, port := range em.inPort { if port == nil { inPorts = append(inPorts, nil) + continue } if port.IsPortExec() { @@ -182,6 +183,7 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) { for _, port := range em.outPort { if port == nil { outPorts = append(outPorts, nil) + continue } if port.IsPortExec() { @@ -396,7 +398,7 @@ func (en *BaseExecNode) GetOutPortArrayValStr(index int, idx int) (Port_Str, boo } func (en *BaseExecNode) GetOutPortBool(index int) (Port_Bool, bool) { - port := en.GetInPort(index) + port := en.GetOutPort(index) if port == nil { return false, false } diff --git a/util/blueprint/graph.go b/util/blueprint/graph.go index 66f3778..855a908 100644 --- a/util/blueprint/graph.go +++ b/util/blueprint/graph.go @@ -47,6 +47,24 @@ type graphContext struct { globalVariables map[string]IPort // 全局变量,g_Return,为执行返回值 } +func clonePortMap(source map[string]IPort) map[string]IPort { + if source == nil { + return nil + } + + target := make(map[string]IPort, len(source)) + for key, port := range source { + if port == nil { + target[key] = nil + continue + } + + target[key] = port.Clone() + } + + return target +} + type nodeConfig struct { Id string `json:"id"` Class string `json:"class"` @@ -153,7 +171,7 @@ func (gr *Graph) GetAndCreateReturnPort() IPort { return p } -func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array, error) { +func (gr *Graph) Do(entranceID int64, args ...any) (ret Port_Array, err error) { if IsDebug { log.Debug("Graph Do", log.String("graphName", gr.graphFileName), log.Int64("graphID", gr.graphID), log.Int64("entranceID", entranceID)) } @@ -166,13 +184,29 @@ func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array, error) { gr.variables = map[string]IPort{} gr.context = map[string]*ExecContext{} + prevGlobalVariables := clonePortMap(gr.globalVariables) + gr.globalVariables = clonePortMap(gr.globalVariables) if gr.globalVariables == nil { gr.globalVariables = map[string]IPort{} - } else { - gr.globalVariables[ReturnVarial] = nil } + gr.globalVariables[ReturnVarial] = nil - err := entranceNode.Do(gr, args...) + defer func() { + if r := recover(); r != nil { + gr.globalVariables = prevGlobalVariables + ret = nil + err = fmt.Errorf("blueprint graph %s entrance %d panic: %v", gr.graphFileName, entranceID, r) + log.StackError( + "blueprint execute panic", + log.String("graphName", gr.graphFileName), + log.Int64("graphID", gr.graphID), + log.Int64("entranceID", entranceID), + log.Any("panic", r), + ) + } + }() + + err = entranceNode.Do(gr, args...) if err != nil { return nil, err } @@ -232,5 +266,6 @@ func (gr *Graph) GetGraphFileName() string { func (gr *Graph) Clone() IGraph { cloneGr := *gr + cloneGr.globalVariables = clonePortMap(gr.globalVariables) return &cloneGr }