# 参数异常：命令缓冲区溢出。无法推送更多命令。最大容量为2048。

- **ID:** `unity/rendering-command-buffer-overflow`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

脚本或着色器向命令缓冲区推送了过多命令，超出默认容量2048。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2021.3 | active | — | — |
| 2022.3 | active | — | — |
| 2023.2 | active | — | — |

## 解决方案

1. ```
   Batch commands using CommandBuffer.Clear before pushing new ones. For example, in an Update loop, call cmdBuffer.Clear() at the start of each frame and rebuild only necessary commands.
   ```
2. ```
   Reduce command count by merging draw calls with MaterialPropertyBlock or using GPU instancing. Replace per-object draw calls with a single DrawMeshInstanced.
   ```
3. ```
   Set CommandBuffer's maximum capacity via reflection (not recommended for production) or offload some commands to a compute shader.
   ```

## 无效尝试

- **** — CommandBuffer capacity is hardcoded internally; no public API exists to change it. Attempting to do so causes compilation errors. (90% 失败率)
- **** — Removing CommandBuffers may break custom rendering effects like outlines or post-processing. (50% 失败率)
- **** — Changing pipeline requires rewriting shaders and materials, which is a large refactor and may not resolve buffer overflow. (70% 失败率)
