From e813ec55750f809bef3e9589db31380903b240d1 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 23 Nov 2023 11:12:37 +0800 Subject: [PATCH] fix --- .../internal/logic/ws_render_image.go | 32 +++++++------------ utils/websocket_data/render_data.go | 5 ++- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 26406921..b73979c3 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -37,7 +37,6 @@ type extendRenderProperty struct { renderCtx context.Context //渲染控制上下文(用于切换模板标签/颜色/logo取消之前发送的不相同的任务) renderCtxCancelFunc context.CancelFunc //渲染控制上下文取消方法 selectColorIndex int //选择的颜色索引(用于标记连接当前连接选择的颜色) - templateTag string //模板标签 (用于标记连接当前连接选择的模板标签) Logo string //logo地址 (用于标记连接当前连接选择的logo) } @@ -52,9 +51,6 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { } //颜色/模板标签/logo变更 ifCancelOldCtx := false - if renderImageData.RenderData.TemplateTag != w.extendRenderProperty.templateTag { - ifCancelOldCtx = true - } if renderImageData.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex { ifCancelOldCtx = true } @@ -63,7 +59,6 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { } if ifCancelOldCtx { //赋值新的 - w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex w.extendRenderProperty.Logo = renderImageData.RenderData.Logo //让之前的失效 @@ -115,23 +110,20 @@ func (w *wsConnectItem) consumeRenderImageData() { defer func() { <-limitChan }() - //如果不是无视上下文切换取消的(后面再开启) - /*if !d.IgnoreContextCancel { - go func() { - defer func() { - if err := recover(); err != nil { - logx.Error("func renderImage panic:", err) - } - }() - select { - case <-w.extendRenderProperty.renderCtx.Done(): - //抛出取消渲染异常 - cancelRenderPanic() - case <-tmpChan: - return + go func() { + defer func() { + if err := recover(); err != nil { + logx.Error("func renderImage panic:", err) } }() - }*/ + select { + case <-w.extendRenderProperty.renderCtx.Done(): + //抛出取消渲染异常 + cancelRenderPanic() + case <-tmpChan: + return + } + }() w.renderImage(d) }(data) } diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 4d39a94d..7bfcb881 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -2,9 +2,8 @@ package websocket_data // websocket接受要云渲染处理的数据 type RenderImageReqMsg struct { - RequestId string `json:"request_id"` - IgnoreContextCancel bool `json:"ignore_context_cancel"` //是否无视切换上下文取消正在执行的渲染任务 - RenderData RenderData `json:"render_data"` //渲染主要参数 + RequestId string `json:"request_id"` + RenderData RenderData `json:"render_data"` //渲染主要参数 } type RenderData struct { TemplateTag string `json:"template_tag"` //模板标签(必须)