{
  "id": "opencv/core-mat-initialization-size-overflow",
  "signature": "cv::error: (-215:Assertion failed) total() == 0 || data != NULL in function 'Mat::create'",
  "signature_zh": "cv::error: (-215:断言失败) total() == 0 || data != NULL 在函数 'Mat::create' 中",
  "regex": "Assertion failed.*total\\(\\) == 0.*data != NULL",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "Creating a cv::Mat with extremely large dimensions (e.g., width or height exceeding memory limits) causes memory allocation failure or overflow, leaving data pointer null.",
  "root_cause_type": "generic",
  "root_cause_zh": "创建具有极大尺寸（例如宽度或高度超过内存限制）的 cv::Mat 会导致内存分配失败或溢出，使数据指针为 null。",
  "versions": [
    {
      "version": "4.5.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.8.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using cv::Mat::zeros with the same large size hoping it handles memory differently",
      "why_fails": "zeros() internally calls create() with the same allocation logic.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Reducing the number of channels to 1 to save memory",
      "why_fails": "If the dimensions are already too large, reducing channels may not be enough; the size itself is the issue.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Allocating on GPU using cv::cuda::GpuMat",
      "why_fails": "GPU memory is even more limited; the same overflow can occur if dimensions exceed GPU memory.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Validate dimensions before creating the matrix: if (width <= 0 || height <= 0 || width > 10000 || height > 10000) { /* handle error */ }",
      "success_rate": 0.9,
      "how": "Validate dimensions before creating the matrix: if (width <= 0 || height <= 0 || width > 10000 || height > 10000) { /* handle error */ }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use cv::Mat::reshape or tiling to process large images in chunks, e.g., cv::Mat tile = img(cv::Rect(0, 0, 1000, 1000));",
      "success_rate": 0.85,
      "how": "Use cv::Mat::reshape or tiling to process large images in chunks, e.g., cv::Mat tile = img(cv::Rect(0, 0, 1000, 1000));",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Validate dimensions before creating the matrix: if (width <= 0 || height <= 0 || width > 10000 || height > 10000) { /* handle error */ }",
    "Use cv::Mat::reshape or tiling to process large images in chunks, e.g., cv::Mat tile = img(cv::Rect(0, 0, 1000, 1000));"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2023-09-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}