{"record":{"id":"a56386b0e7c4b037","repo":"egametang/ET","slug":"pathfinding-ptr-is-zero-self-scene-name","errorCode":null,"errorMessage":"pathfinding ptr is zero: {self.Scene().Name}","messagePattern":"pathfinding ptr is zero: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.recast/Scripts/Hotfix/Share/PathfindingComponentSystem.cs","lineNumber":41,"sourceCode":"            }\n            \n            self.filter = new DtQueryDefaultFilter();\n            self.query = new DtNavMeshQuery(self.navMesh);\n        }\n\n        [EntitySystem]\n        private static void Destroy(this PathfindingComponent self)\n        {\n            self.Name = string.Empty;\n            self.navMesh = null;\n        }\n        \n        public static void Find(this PathfindingComponent self, float3 start, float3 target, List<float3> result)\n        {\n            if (self.navMesh == null)\n            {\n                Log.Debug(\"寻路| Find 失败 pathfinding ptr is zero\");\n                throw new Exception($\"pathfinding ptr is zero: {self.Scene().Name}\");\n            }\n\n            RcVec3f startPos = new(-start.x, start.y, start.z);\n            RcVec3f endPos = new(-target.x, target.y, target.z);\n\n            long startRef;\n            long endRef;\n            RcVec3f startPt;\n            RcVec3f endPt;\n            \n            self.query.FindNearestPoly(startPos, self.extents, self.filter, out startRef, out startPt, out _);\n            self.query.FindNearestPoly(endPos, self.extents, self.filter, out endRef, out endPt, out _);\n            \n            self.query.FindPath(startRef, endRef, startPt, endPt, self.filter, ref self.polys, new DtFindPathOption(0, float.MaxValue));\n\n            if (0 >= self.polys.Count)\n            {\n                return;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Hotfix/Share/PathfindingComponentSystem.cs#L23-L59","documentation":"The Find(start, target, result) method guards against a null navMesh field. Because Destroy() sets navMesh to null, this fires when Find is called on a PathfindingComponent that was destroyed, or one whose Awake failed (so navMesh was never assigned).","triggerScenarios":"Calling entity.FindPath / PathfindingComponent.Find() on a component whose self.navMesh is null. This includes: post-Destroy usage, components created without a successful Awake (see error 309), or logic that retained a stale component reference after teardown.","commonSituations":"EntityRef holding a PathfindingComponent across an await during which the entity (and component) was destroyed; scene teardown ordering where pathfinding requests are still in-flight; a system calling Find without checking component liveness.","solutions":["Re-acquire the PathfindingComponent via EntityRef after any await and null-check before calling Find.","Ensure no pathfinding requests are queued after scene/entity destruction (cancel timers / pending work).","Guard call sites: check the entity/component is not disposed before invoking Find.","Fix destroy ordering so pathfinding users are torn down before the navmesh component."],"exampleFix":"// before: stale ref after await\nEntityRef<PathfindingComponent> navRef = comp;\nawait ...;\ncomp.Find(start, target, result);\n// after: re-acquire and validate\nEntityRef<PathfindingComponent> navRef = comp;\nawait ...;\ncomp = navRef;\nif (comp == null || comp.IsDisposed) return;\ncomp.Find(start, target, result);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool CanPathfind(this PathfindingComponent c) => c != null && !c.IsDisposed && c.navMesh != null;","tryCatchPattern":null,"preventionTips":["Re-acquire PathfindingComponent via EntityRef after every await.","Cancel pathfinding requests when the owning entity is destroyed.","Tear down pathfinding users before the navmesh component."],"tags":["recast","pathfinding","lifecycle","null-reference","entityref"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}