{"record":{"id":"2d061f37f4344bf4","repo":"tonhowtf/omniget","slug":"sem-memoria-para-x","errorCode":null,"errorMessage":"sem memoria para {}x{}","messagePattern":"sem memoria para (.+?)x(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":333,"sourceCode":"struct PageRef<'a> {\n    api: &'static Api,\n    page: Page,\n    _doc: &'a Document,\n}\n\nimpl PageRef<'_> {\n    fn size_pt(&self) -> (f32, f32) {\n        unsafe { ((self.api.page_w)(self.page), (self.api.page_h)(self.page)) }\n    }\n\n    fn render(&self, dpi: u32) -> anyhow::Result<image::RgbImage> {\n        let (w_pt, h_pt) = self.size_pt();\n        let scale = dpi.max(24) as f32 / 72.0;\n        let w = ((w_pt * scale).round() as i32).clamp(1, 20_000);\n        let h = ((h_pt * scale).round() as i32).clamp(1, 20_000);\n        let bmp = unsafe { (self.api.bmp_create)(w, h, 0) };\n        if bmp.is_null() {\n            return Err(anyhow!(\"sem memoria para {}x{}\", w, h));\n        }\n        let mut img = image::RgbImage::new(w as u32, h as u32);\n        unsafe {\n            (self.api.bmp_fill)(bmp, 0, 0, w, h, 0xFFFF_FFFF);\n            (self.api.render)(bmp, self.page, 0, 0, w, h, 0, FPDF_ANNOT);\n            let stride = (self.api.bmp_stride)(bmp) as usize;\n            let buf = (self.api.bmp_buffer)(bmp) as *const u8;\n            let src = std::slice::from_raw_parts(buf, stride * h as usize);\n            for y in 0..h as usize {\n                let row = &src[y * stride..y * stride + w as usize * 4];\n                for x in 0..w as usize {\n                    let p = &row[x * 4..x * 4 + 4]; // BGRx\n                    img.put_pixel(x as u32, y as u32, image::Rgb([p[2], p[1], p[0]]));\n                }\n            }\n            (self.api.bmp_destroy)(bmp);\n        }\n        Ok(img)","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L315-L351","documentation":"Allocation guard in PageRef render: the MuPDF bitmap of the computed pixel dimensions could not be created — the w×h at the chosen DPI exceeds available memory — so rasterizing this page at this resolution is impossible.","triggerScenarios":"Calling render (directly or via the live preview path) with a DPI/zoom that, applied to a very large page, yields bitmap dimensions near the 20000×20000 clamp — e.g. a huge-format page (posters, blueprints) at 300+ DPI.","commonSituations":"Rendering A0/architectural drawings at high DPI, previewing zoomed-in pages of large-format PDFs, memory-constrained environments where even modest bitmaps fail to allocate.","solutions":["Lower the DPI (e.g. from 300 to 96–150) and retry","Cap rendered dimensions: compute w*h beforehand and reduce DPI so the product stays reasonable","Check available memory; a w×h RGB bitmap needs ~3*w*h bytes","Skip or stub rendering for pages whose computed dimensions are extreme"],"exampleFix":"// before\nlet scale = dpi.max(24) as f32 / 72.0;\n// after\nlet scale = (dpi.max(24) as f32 / 72.0).min(max_scale_for(w_pt, h_pt));\n// where max_scale_for keeps w_pt*scale*h_pt*scale under ~50M pixels","handlingStrategy":"validation","validationCode":"let (w, h) = computed_dimensions(page, dpi);\nanyhow::ensure!(w <= 20_000 && h <= 20_000 && (w as u64) * (h as u64) <= 80_000_000, \"dpi {dpi} too high for this page\");","typeGuard":null,"tryCatchPattern":"match page.render(dpi) {\n    Ok(img) => img,\n    Err(e) if e.to_string().starts_with(\"sem memoria\") => page.render(dpi / 2).context(\"rendering failed even at half DPI\")?,\n    Err(e) => return Err(e),\n}","preventionTips":["Cap DPI based on page size so w*h stays under ~50–80M pixels","Offer a DPI selector with a sane default (96–150) in UIs","Watch memory headroom in containers before rendering large pages","Add an automatic DPI-halving retry for large-format pages"],"tags":["ffi","pdf","rendering","memory-allocation"],"backgroundTag":"value-out-of-range","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}