EllanJiang/GameFramework · error · GameFrameworkException
Event is invalid.
Error message
Event is invalid.
What it means
EventPool.Fire validates that the event argument object e is not null before enqueuing it for deferred dispatch. A null event payload cannot carry an event id (e.Id) for routing, so the library throws GameFrameworkException immediately at the Fire call site.
Solutions
- Create a valid event args instance (e.g. via ReferencePool.Acquire) before calling Fire.
- Add a null check at the call site or in wrapper code so a null never reaches Fire.
- Fix the event args factory that returned null.
- If the event legitimately has no data, use an existing non-null args type instead of null.
Example fix
// before
OpenUIEventArgs e = GetArgsMaybeNull();
m_EventComponent.Fire(this, e);
// after
OpenUIEventArgs e = GetArgsMaybeNull();
if (e != null) { m_EventComponent.Fire(this, e); } Defensive patterns
Strategy: validation
Validate before calling
if (eventArgs == null) throw new InvalidOperationException("Event args must be created before Fire."); eventComponent.Fire(sender, eventArgs); Type guard
static bool IsValidArgs<T>(T e) where T : class => e != null;
Try / catch
try { pool.Fire(sender, e); } catch (GameFrameworkException ex) { Log.Error("Attempted to fire a null event: {0}", ex.Message); } Prevention
- Always acquire event args from ReferencePool before firing
- Add null checks in wrapper/helper fire methods
- Avoid generic fire APIs that can receive default(T)
When it happens
Trigger: Calling Fire(object sender, T e) with e == null, typically from a helper that builds the event args conditionally, or passing a null reference from an uninitialized event-args variable.
Common situations: A factory/ReferencePool.Get call returning null when the event args class isn't pooled; refactored code that removed event args creation but left Fire(eventArgs) in place; generic wrappers passing default(T) which is null for reference types.
Related errors
- Event ' ' not allow no handler.
- Owner is invalid.
- Resource manager is invalid.
- Data provider helper is invalid.
- Type is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/15820fe77df8d1e3.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Base/EventPool/EventPool.cs:222
/// <summary>
/// 设置默认事件处理函数。
/// </summary>
/// <param name="handler">要设置的默认事件处理函数。</param>
public void SetDefaultHandler(EventHandler<T> handler)
{
m_DefaultHandler = handler;
}
/// <summary>
/// 抛出事件,这个操作是线程安全的,即使不在主线程中抛出,也可保证在主线程中回调事件处理函数,但事件会在抛出后的下一帧分发。
/// </summary>
/// <param name="sender">事件源。</param>
/// <param name="e">事件参数。</param>
public void Fire(object sender, T e)
{
if (e == null)
{
throw new GameFrameworkException("Event is invalid.");
}
Event eventNode = Event.Create(sender, e);
lock (m_Events)
{
m_Events.Enqueue(eventNode);
}
}
/// <summary>
/// 抛出事件立即模式,这个操作不是线程安全的,事件会立刻分发。
/// </summary>
/// <param name="sender">事件源。</param>
/// <param name="e">事件参数。</param>
public void FireNow(object sender, T e)
{
if (e == null)
{View on GitHub (pinned to d0c010b051)