Skip to content

Traps index (语义陷阱索引) ​

KB-001 bucket ④: an index of the semantic traps and easy-to-misread behaviors collected across this knowledge base. Each row points at the article carrying the full 现象/根因/正确姿势 (symptom / grounded root cause / correct pattern) — this page never introduces a claim the target article does not already ground. Root-cause citations live in the target articles; the grounding commit per article is in its header.

Memory & references ​

TrapSymptomCorrect patternDetails
Holding a destroyed entity in a closure/listgarbages not emptied; after 3600 s the engine logs a leak warningDrop references in onDestroy; query KBEngine.entities.garbages.items() to find holderslifecycle §Registry
destroy() during __init__AssertionError "initing, reject the request"Defer destruction to after initlifecycle §Guards
Method call on a destroyed entity (local)AssertionError "is destroyed"Guard with entity.isDestroyedlifecycle §Guards
Remote call targeting a destroyed entityNo exception at the caller — a logged ERROR_MSG/WARNING_MSG at the receiver, message droppedTreat remote fire-and-forget as best-effort; confirm via callback if it matterslifecycle §Guards, migration §Rules
Worrying about BigWorld-style "Functor" reference leaksNo Functor class exists in KBEngine; the async-callback holder is PY_CALLBACKMGR — strong ref per pending callback, released on answer/timeout/finalisePending callbacks cannot outlive the timeout nor keep a destroyed entity alivelifecycle §Functor

Migration & teleport ​

TrapSymptomCorrect patternDetails
Ghost cannot teleportAssertionError "not is real entity"Teleport from the real entitymigration §Teleport
Micro-jump inside a trapTrap leave and enter callbacks both fire (teleport counts as instant move)Expect both callbacks on any teleport, regardless of distancemigration §Teleport
Wrong ref type to teleport (e.g. a base EntityCall)onTeleportFailurePass a cell-real EntityCall (or the entity itself / None)migration §Teleport
Assuming old cell's onDestroy runs after cross-cellapp teleportIt never fires — the old entity is destroyed with callScript=false; onTeleportSuccess fires on the new cell, onTeleportFailure restores the old onePut per-space cleanup in onLeaveSpace, not onDestroy-assumptionsmigration §Completion
Stale separately-held EntityCall copy after migrationMessage silently dropped at the old cellapp (WARNING_MSG entityID ... not found)Re-read self.cell/self.base at use time instead of caching the handlemigration §Rules
Reading self.cellData while the cell livesAttributeError (attribute is deleted; values are defaults or last dirty backup anyway)Use self.cell.<method> calls; treat cellData as a no-cell-era snapshot onlymigration §cellData

Timers & controllers ​

TrapSymptomCorrect patternDetails
delTimer with a stale id expecting an errorReturns -1 silently (fork); the 3.7 material claims an errorCheck the return valueapi-cellapp-entity §deviations
Expecting to cancel timers in onDestroyUnnecessary — destroy() cancels all timers (scriptTimers_.cancelAll())Only delTimer matters for early cancel while alivelifecycle §Timers, usage stats
cancelController("SomeType")TypeError — only the exact string "Movement" is acceptedCancel by handle for other controllersapi-cellapp-entity §deviations
Calling trackEntity / turnToYawNo such methods in the forkmoveToEntity / addYawRotatorapi-cellapp-entity §deviations
Module-level KBEngine.addTimer with a self-bound callback leaksThe app-level timer strongly refs the callback object (self.onTick strongly refs the entity); entity destroy() cancels only the entity's own scriptTimers_, never this one — the callback keeps firing / the entity leaks into garbagesStore the handle and call KBEngine.delTimer(handle) in onDestroy (entity-level self.addTimer is safe — destroy auto-cancels all)lifecycle §Timers, python_app.cpp:721-748

Property sync ​

TrapSymptomCorrect patternDetails
FIXED_DICT sub-key assignment does not syncself.<FIXED_DICT property>[subKey] = value only mutates the local pyDict_; the engine has no notification hook there, so the property never syncsWhole-reassign idiom: d = self.<prop> → mutate sub-key → self.<prop> = d (only top-level assignment syncs)core-concepts §1.5, fixeddict.cpp:272-308

EntityCall semantics ​

TrapSymptomCorrect patternDetails
Calling an engine method through an EntityCallNot reachable — an EntityCall only invokes methods declared in the .def fileDeclare the method in def, or use a local entity reference for engine APIsapi-core-concepts §1.1

Callback naming & face placement ​

TrapSymptomCorrect patternDetails
Project-defined onXxx handlers mistaken for engine callbacks~1/3 of def onXxx definitions in real trees are project conventions, engine never calls themCheck the callback tables before assuming a name is engine-calledusage stats, entry SPI table
onReadyForLogin return-value semanticsNot "≥ 1.0 means ready" — True → ready; float completes at >= 0.9999; no callback → immediately completeReturn a True/float progress per the fork semanticsapi-cellapp §deviations
Expecting onDestroy on the embedded clientNever dispatched (empty C++ override, callScript=false on remote destroy)Handle client-side cleanup elsewhereapi-client §deviations

Client-face API availability ​

TrapSymptomCorrect patternDetails
KBEngine.login/createAccount/... as client Python functionsNot registered on any Python surface in kbe/src (plugin-layer, outside this repo)Use the plugin SDK's functions, not the engine moduleapi-client §deviations
KBEngine.findEntity(id)No such registrationKBEngine.entities[entityID]api-client §deviations

Source-material hygiene ​

TrapSymptomCorrect patternDetails
Copying examples from the 3.7 CHMPython 2 syntax (print "...") does not run on 3.12Rewrite snippets; treat material tables as leads, the fork source as truthapi-cellapp §deviations

Kode documentation