Tauri WSL2 gdk-pixbuf Crash Fix
Problem
Tauri v2 desktop application crashes immediately on startup when running in WSL2 (Windows Subsystem for Linux) with WSLg. The panic occurs in the gdk-pixbuf crate before the window can render.
Context / Trigger Conditions
Error message:
thread 'main' panicked at /home/user/.cargo/registry/src/.../gdk-pixbuf-0.18.5/src/pixbuf.rs:44:13:
data.len() must fit the width, height, and row_stride
When this occurs:
- Running Tauri v2 app on WSL2 with WSLg (GUI support)
- App compiles successfully but crashes on
Runningstep - Icons are configured in
tauri.conf.jsonunderbundle.icon - DISPLAY and WAYLAND_DISPLAY environment variables are set
- Crash happens even with valid PNG files (32x32, 128x128, etc.)
NOT this issue if:
- App fails during compilation
- Error mentions missing libraries (install GTK dependencies instead)
- App runs but window doesn't appear (display server issue)
Solution
Quick Fix
Set an empty icon array in tauri.conf.json:
{
"bundle": {
"active": true,
"targets": "all",
"icon": []
}
}
Why This Works
The gdk-pixbuf library in GTK has issues loading certain icon formats or dimensions in the WSL2/WSLg environment. By providing an empty icon array, Tauri skips the problematic icon loading during window initialization. The app will use a default system icon instead.
Alternative: Ensure Icons are Proper RGBA
If you need custom icons, ensure they are:
- True color RGBA (not indexed/palette)
- Created with proper color depth:
convert -size 32x32 xc:'#3b82f6' -type TrueColorAlpha -define png:color-type=6 icon.png - Standard dimensions (32x32, 128x128, 256x256)
Even with proper icons, the empty array workaround may still be needed on WSL2.
Verification
After applying the fix:
- Run
npm run tauri:devorcargo tauri dev - App should compile and show
Running /path/to/app - Window should appear without panic
- Check with
ps aux | grep your-app-nameto confirm process is running
Example
Before (crashes):
{
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/icon.png"
]
}
}
After (works):
{
"bundle": {
"active": true,
"targets": "all",
"icon": []
}
}
Notes
- This is a WSL2/Linux-specific issue; the same app typically works fine on Windows and macOS
- The fix only affects the development/bundle icons, not runtime functionality
- For production Linux builds, you may need to test on actual Linux to see if the issue persists
- The empty icon array results in a generic/default window icon
- This issue is related to how GTK's gdk-pixbuf handles icon data in the WSLg compositor environment
- Future Tauri or GTK updates may resolve this; check if the issue persists after updates
Related Issues
- Tauri apps on WSL2 may also require proper DISPLAY/WAYLAND_DISPLAY setup
- If app runs but window doesn't appear, check
echo $DISPLAYand/mnt/wslg/exists - For "cannot open display" errors, ensure WSLg is installed and running
