{"record":{"id":"c86c7285cdafe653","repo":"EllanJiang/GameFramework","slug":"object-is-invalid","errorCode":null,"errorMessage":"Object is invalid.","messagePattern":"Object is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/ObjectPool/ObjectPoolManager.Object.cs","lineNumber":127,"sourceCode":"            public int SpawnCount\n            {\n                get\n                {\n                    return m_SpawnCount;\n                }\n            }\n\n            /// <summary>\n            /// 创建内部对象。\n            /// </summary>\n            /// <param name=\"obj\">对象。</param>\n            /// <param name=\"spawned\">对象是否已被获取。</param>\n            /// <returns>创建的内部对象。</returns>\n            public static Object<T> Create(T obj, bool spawned)\n            {\n                if (obj == null)\n                {\n                    throw new GameFrameworkException(\"Object is invalid.\");\n                }\n\n                Object<T> internalObject = ReferencePool.Acquire<Object<T>>();\n                internalObject.m_Object = obj;\n                internalObject.m_SpawnCount = spawned ? 1 : 0;\n                if (spawned)\n                {\n                    obj.OnSpawn();\n                }\n\n                return internalObject;\n            }\n\n            /// <summary>\n            /// 清理内部对象。\n            /// </summary>\n            public void Clear()\n            {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/ObjectPool/ObjectPoolManager.Object.cs#L109-L145","documentation":"Object<T>.Create is the internal factory that wraps a pooled object for ObjectPoolManager. It requires a non-null obj and throws 'Object is invalid.' otherwise. This is the inner guard behind ObjectPool.Register, so the pool never holds entries with null payloads.","triggerScenarios":"Calling ObjectPool.Register(obj, spawned) with a null obj, which reaches Object<T>.Create and throws; also any direct use of Object<T>.Create with null.","commonSituations":"Resource load failure producing null which is then registered; API returning null on cache miss being passed straight to Register; generic T being a reference type with an uninitialized variable.","solutions":["Null-check the object before calling Register and abort or log the load failure","Ensure the object producer (loader, factory, spawner) cannot silently return null","Fix the upstream creation code that produced null"],"exampleFix":"// before\nobjectPool.Register(loadedObject, false); // loadedObject may be null\n// after\nif (loadedObject != null) { objectPool.Register(loadedObject, false); }","handlingStrategy":"validation","validationCode":"if (obj == null) { Log.Error(\"Cannot register null object\"); return; }\nobjectPool.Register(obj, spawned);","typeGuard":"bool IsRegisterable<T>(T obj) where T : class => obj != null;","tryCatchPattern":"try { objectPool.Register(obj, spawned); }\ncatch (GameFrameworkException ex) { Log.Error(\"Invalid object for pool: {0}\", ex.Message); }","preventionTips":["Guard all producers of pooled objects for null","Never pass raw load results directly to Register","Use ArgumentNullException in your own factories"],"tags":["objectpool","null-argument","gameframework"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}