{
  "id": "unity/graphics-buffer-mismatch",
  "signature": "ArgumentException: Buffer 'MyBuffer' has been declared as a structured buffer in the shader, but the C# script is binding a different type (ComputeBuffer or GraphicsBuffer)",
  "signature_zh": "ArgumentException: 缓冲区'MyBuffer'在着色器中声明为结构化缓冲区，但C#脚本绑定了不同类型的缓冲区（ComputeBuffer或GraphicsBuffer）",
  "regex": "ArgumentException: Buffer '.*' has been declared as a structured buffer in the shader, but the C# script is binding a different type",
  "domain": "unity",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Mismatch between the buffer type declared in the HLSL shader (e.g., StructuredBuffer) and the buffer type created in C# (e.g., ComputeBuffer with wrong stride or GraphicsBuffer with wrong target).",
  "root_cause_type": "generic",
  "root_cause_zh": "HLSL着色器中声明的缓冲区类型（例如StructuredBuffer）与C#中创建的缓冲区类型（例如ComputeBuffer步幅错误或GraphicsBuffer目标错误）不匹配。",
  "versions": [
    {
      "version": "Unity 2022.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2023.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Increasing the buffer size does not fix type mismatch; the issue is stride or target, not capacity.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Switching to a different shader variant does not change the buffer declaration mismatch.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the C# ComputeBuffer stride equals the size of the struct used in the shader. For a float3 buffer, stride = 12 bytes. Example: ComputeBuffer buffer = new ComputeBuffer(count, sizeof(float) * 3); shader.SetBuffer(kernel, \"MyBuffer\", buffer);",
      "success_rate": 0.9,
      "how": "Ensure the C# ComputeBuffer stride equals the size of the struct used in the shader. For a float3 buffer, stride = 12 bytes. Example: ComputeBuffer buffer = new ComputeBuffer(count, sizeof(float) * 3); shader.SetBuffer(kernel, \"MyBuffer\", buffer);",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using GraphicsBuffer, set the correct target (e.g., GraphicsBuffer.Target.Structured). Example: GraphicsBuffer gfxBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, count, stride);",
      "success_rate": 0.85,
      "how": "If using GraphicsBuffer, set the correct target (e.g., GraphicsBuffer.Target.Structured). Example: GraphicsBuffer gfxBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, count, stride);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure the C# ComputeBuffer stride equals the size of the struct used in the shader. For a float3 buffer, stride = 12 bytes. Example: ComputeBuffer buffer = new ComputeBuffer(count, sizeof(float) * 3); shader.SetBuffer(kernel, \"MyBuffer\", buffer);",
    "If using GraphicsBuffer, set the correct target (e.g., GraphicsBuffer.Target.Structured). Example: GraphicsBuffer gfxBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, count, stride);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/Manual/compute-shaders.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-11-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}