bilibili/DanmakuFlameMaster · error · IllegalArgumentException
context is null
Error message
context is null
What it means
DrawTask's constructor requires a non-null DanmakuContext; it immediately derives the Displayer and DanmakuRenderer from it, so a null context would make the whole draw pipeline unusable. The library fails fast with IllegalArgumentException rather than NPE-ing later during rendering.
Solutions
- Create a DanmakuContext first with DanmakuContext.create() and pass it to the constructor.
- Check that the variable passed as context is assigned before the DrawTask/DanmakuView setup runs.
- If using DanmakuView, ensure prepare() is called after the view has initialized its own context, not with a hand-built null context.
- Wrap the setup call in a null check or Objects.requireNonNull(context) at the call site to catch it early.
Example fix
// before DrawTask task = new DrawTask(timer, null, listener); // after DanmakuContext context = DanmakuContext.create(); DrawTask task = new DrawTask(timer, context, listener);
Defensive patterns
Strategy: validation
Validate before calling
if (context == null) { throw new IllegalStateException("call DanmakuContext.create() before constructing DrawTask"); }
DrawTask task = new DrawTask(timer, context, listener); Type guard
boolean hasContext = (context != null);
Try / catch
try {
DrawTask task = new DrawTask(timer, context, listener);
} catch (IllegalArgumentException e) {
Log.e(TAG, "DrawTask needs a DanmakuContext", e);
context = DanmakuContext.create();
} Prevention
- Always create the context via DanmakuContext.create() before preparing the danmaku view.
- Never pass a possibly-async-assigned context into view setup; await its assignment first.
- Assert non-null context in your own wrapper around DrawTask.
When it happens
Trigger: Calling new DrawTask(timer, null, taskListener), or creating it indirectly (e.g. DanmakuView/DanmakuSurfaceView initialize paths) after DanmakuContext was never created via DanmakuContext.create().
Common situations: Forgetting to call DanmakuContext.create() before preparing the danmaku view; passing a context variable that is assigned asynchronously and still null when the draw task is built; custom controller code constructing DrawTask manually.
Related errors
AI-assisted analysis of bilibili/DanmakuFlameMaster@e2846461a0 (2026-09-10).
Data as JSON: /api/errors/567acb1d09435a64.
Report an issue: GitHub.
Appendix: source
Thrown at DanmakuFlameMaster/src/main/java/master/flame/danmaku/controller/DrawTask.java:87
private BaseDanmaku mLastDanmaku;
private Danmakus mLiveDanmakus = new Danmakus(Danmakus.ST_BY_LIST);
private IDanmakus mRunningDanmakus;
private boolean mRequestRender;
private ConfigChangedCallback mConfigChangedCallback = new ConfigChangedCallback() {
@Override
public boolean onDanmakuConfigChanged(DanmakuContext config, DanmakuConfigTag tag, Object... values) {
return DrawTask.this.onDanmakuConfigChanged(config, tag, values);
}
};
public DrawTask(DanmakuTimer timer, DanmakuContext context,
TaskListener taskListener) {
if (context == null) {
throw new IllegalArgumentException("context is null");
}
mContext = context;
mDisp = context.getDisplayer();
mTaskListener = taskListener;
mRenderer = new DanmakuRenderer(context);
mRenderer.setOnDanmakuShownListener(new IRenderer.OnDanmakuShownListener() {
@Override
public void onDanmakuShown(BaseDanmaku danmaku) {
if (mTaskListener != null) {
mTaskListener.onDanmakuShown(danmaku);
}
}
});
mRenderer.setVerifierEnabled(mContext.isPreventOverlappingEnabled() || mContext.isMaxLinesLimited());
initTimer(timer);
Boolean enable = mContext.isDuplicateMergingEnabled();
if (enable != null) {
View on GitHub (pinned to e2846461a0)