Merge pull request '更新 GiDrawUtility 分析文档:补充修复状态与 S3 误判结论' (#68) from home-lenovo-legion-r9000/doc-gidrawutility-analysis-status into main

Reviewed-on: #68
This commit was merged in pull request #68.
This commit is contained in:
gjm committed 2026-10-25 19:10:10 +08:00
commit bc7bf7b15b
1 file changed
+43 -2
+43 -2
View File
@@ -3,9 +3,9 @@
> 目标:在动手改之前,把 `GiDrawUtility`(AecRxBase 公共几何工具库)的内存泄漏、性能热点和逻辑缺陷列清楚,给出可分批落地的修复顺序。
>
> 范围:`SourceCode/Code2026/AecRxBase/GiDrawUtility.cpp`(965 行)、`SourceCode/Code2026/inc/GiDrawUtility.h`。
> 关联:`EarThwormDef.h`(DELETE_PTR / EQUAL_ZERO 宏)、`inc/AdsXRx/tsuperlist.h`(DELETE_PTR 定义)。
> 关联:`EarThwormDef.h`(EQUAL_ZERO 等宏)、`inc/memOper.h`(DELETE_PTR 模板函数,经 `KTCad.h` 的 `using namespace MemOper;` 引入)。
>
> 状态(2026-10-25):仅分析,未改代码。行号以当前 main 为准。
> 状态(2026-10-25):L1-L7、B1-B5、B7、B9、S1 已修复并合并(PR #62 / #64 / #65 / #67);B6、B8、B10、B11、S2 确认不改;S3 复核为误判。详见第 7 节。文中行号为分析时的 main,修复后已偏移。
## 1. 背景与影响面
@@ -148,3 +148,44 @@ if (!pReg) { _pC->setColorIndex(1); AddToModelSpace(_pC); return NULL; }
5. 其余(B2/B3/B5~B8/B10/B11、E 系列、S 系列)按需。
注意事项:GiDrawUtility 是 AecRxBase 公共库、DrawPipe 系列是全库管道实体绘制的公共入口,改动后建议小步提交,编译对应 preset 并在 CAD 中实测(画管、台体、回转体、loft 分解)。
## 7. 处理结果(2026-10-25)
### 7.1 已修复
| # | 内容 | 落地 |
| --- | --- | --- |
| L1 / L2 | `DrawPipe(ptFrom, ptTo)` 重复建 region、`pSml` 成功后不释放 | PR #62 |
| L3 ~ L6 | 各失败路径补释放:`DrawLoft(curve,curve,curve)`、`DrawBox`、`DrawSphere`、`DrawMesh`、`DrawPipe(pCurve, dR)` 的 ARX 分支 | PR #62 |
| L7 | 新增 `TakeFirstRegion()`,`createRegion(AcDbEntity*)`、`DrawDish`、`DrawPipe(pCurve, dR)` 统一只取首个 region 并释放其余;`DrawDish` 顺带补上 `DrawRevolve` 失败时的释放 | PR #65 |
| B1 | `RotateAndMove` 平移项改为 `ptDist - R*ptOrig` | PR #64 |
| B2 | 零向量显式退化为 Z 轴,去掉 `*= 1` 空操作 | PR #65 |
| B3 | `DrawTydf` 的 tfdy 分支引导线跟随变换后的截面中心 | PR #65 |
| B4 | `DrawMesh` 入参校验(`pVertexList`、`rows >= 2`、`columns >= 3`) | PR #65 |
| B5 | `DrawRevolve` 建 region 失败不再往模型空间塞红色曲线 | PR #65 |
| B7 | `DrawPipe(pCurve, dR)` 检查 `getStartPoint` 返回值 | PR #67 |
| B9 | `DrawDish` 除零、`DrawCirTorus`/`DrawRectTorus` 负半径、零长管道、非正半径 | PR #67 |
| S1 | `spliteCurve`、`deleteContainerOfArx` 由文件级 `static` 移入匿名 namespace | PR #67 |
E1 随 L1 一并消除(不再对同一几何重复调用 `createFromCurves`)。
### 7.2 确认不改
B6(`nSegs` 死参数,删除需改公开签名)、B8(`create3DPolyline` 强制闭合)、B10(`DrawExclude` 用包围盒中心作拉伸起点)、B11(三个 `AddToModelSpace` 重载为调试用函数)、S2(`transfromRegion` 拼写不改名,避免动公开 API)。
### 7.3 S3 结论:误判,不改宏
`GiDrawUtility.cpp` 里的 `DELETE_PTR` 不来自 `tsuperlist.h` 的宏,而是 `inc/KTCad.h:565` 的 `using namespace MemOper;` 引入的模板函数:
```cpp
// inc/memOper.h
template <class T>
void DELETE_PTR(T *&ptr) { if (ptr != NULL) { delete ptr; ptr = NULL; } }
```
模板函数不存在悬垂 else 问题,本文件不受影响。`inc/AdsXRx/tsuperlist.h`、`tg_shs/inc/geo/tsuperlist.h` 的 `DELETE_PTR` 宏与 `Dimension/superlist.h` 的 `_DELETE_PTR_` 宏仍是 `if (ptr) { ... }` 形式,但与本文件无关,保持原样。
### 7.4 未处理(纯效率项)
E2(分段递归时每段重建模板 region)、E3(`transfromRegion` 两次 `transformBy`)、E4(`DrawPyramid`/`DrawTydf` 的恒等平移)、E5(`DrawSphere` 同轴 `rotateTo` 返回单位阵)——只影响性能,不影响正确性,暂不处理。