wasabeef/android-gpuimage · error · IllegalStateException
setRenderer has already been called for this instance.
Error message
setRenderer has already been called for this instance.
What it means
GLTextureView allows setRenderer() only once per instance; checkRenderThreadState() throws IllegalStateException when the GLThread already exists. Re-attempting initialization (setRenderer/setGLWrapper) on the same view would leak a second render thread, so it is rejected.
Solutions
- Call setRenderer() exactly once per GLTextureView instance; guard with a boolean flag.
- On configuration changes, create a new GPUImage/GPUImageView setup instead of reusing the old view.
- Wrap the call: only invoke setRenderer if the renderer has not been installed yet.
Example fix
// before
gpuImageView.setRenderer(renderer); // may run again on re-attach
// after
if (!rendererSet) {
gpuImageView.setRenderer(renderer);
rendererSet = true;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (rendererAlreadySet) { return; } Try / catch
try {
gpuImageView.setRenderer(renderer);
} catch (IllegalStateException e) {
// renderer already installed on this instance; safe to ignore or recreate the view
} Prevention
- Set the renderer once, guarded by a boolean (e.g. in a single init method)
- Recreate the view on configuration changes instead of re-initializing
- Do not call setRenderer from callbacks that can fire multiple times (onAttachedToWindow)
When it happens
Trigger: Calling setRenderer() a second time on the same GLTextureView — e.g. re-initializing after onConfigurationChanged/orientation change, re-entering a Fragment/Activity lifecycle callback, or a retry path that re-attaches the renderer.
Common situations: Fragment views recreated without tearing down state; onAttachedToWindow invoked twice; retrying GPUImage setup after a failure without a new view instance; retaining the old view across config changes.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- eglChooseConfig failed
- egl not initialized
- eglDisplay not initialized
- eglConfig not initialized
- renderMode
AI-assisted analysis of wasabeef/android-gpuimage@ceea576ec9 (2026-09-11).
Data as JSON: /api/errors/f08c327a454a2945.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/jp/co/cyberagent/android/gpuimage/GLTextureView.java:1689
} else {
builder.append(c);
}
}
}
private void flushBuilder() {
if (builder.length() > 0) {
Log.v("GLTextureView", builder.toString());
builder.delete(0, builder.length());
}
}
private StringBuilder builder = new StringBuilder();
}
private void checkRenderThreadState() {
if (glThread != null) {
throw new IllegalStateException("setRenderer has already been called for this instance.");
}
}
private static class GLThreadManager {
private static String TAG = "GLThreadManager";
public synchronized void threadExiting(GLThread thread) {
if (LOG_THREADS) {
Log.i("GLThread", "exiting tid=" + thread.getId());
}
thread.exited = true;
if (eglOwner == thread) {
eglOwner = null;
}
notifyAll();
}
/*View on GitHub (pinned to ceea576ec9)