{"record":{"id":"cda95f0efa08e91b","repo":"Yalantis/uCrop","slug":"render-empty-specified-image","errorCode":null,"errorMessage":"render(): Empty specified image.","messagePattern":"render\\(\\): Empty specified image\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":12545,"sourceCode":"                                     (int)_width,(int)_height);\n      }\n      SDL_UpdateTexture(_texture,0,_data,_width*sizeof(unsigned int));\n      SDL_RenderClear(_renderer);\n      SDL_FRect rect;\n      rect.x = rect.y = 0;\n      rect.w = (float)_width;\n      rect.h = (float)_height;\n      SDL_RenderTexture(_renderer,_texture,0,&rect);\n      SDL_RenderPresent(_renderer);\n      _paint_request = false;\n      SDL3_attr.unlock();\n      return *this;\n    }\n\n    template<typename T>\n    CImgDisplay& render(const CImg<T>& img) {\n      if (!img)\n        throw CImgArgumentException(_cimgdisplay_instance\n                                    \"render(): Empty specified image.\",\n                                    cimgdisplay_instance);\n\n      if (is_empty()) return *this;\n      if (img._depth!=1) return render(img.get_projections2d((img._width - 1)/2,(img._height - 1)/2,\n                                                             (img._depth - 1)/2));\n      cimg::SDL3_attr &SDL3_attr = cimg::SDL3_attr::ref();\n      SDL3_attr.lock();\n      const T\n        *data1 = img._data,\n        *data2 = (img._spectrum>=2)?img.data(0,0,0,1):data1,\n        *data3 = (img._spectrum>=3)?img.data(0,0,0,2):data1;\n\n      unsigned int\n        *const ndata = (img._width==_width && img._height==_height)?_data:\n        new unsigned int[(size_t)img._width*img._height],\n        *ptrd = ndata;\n","sourceCodeStart":12527,"sourceCodeEnd":12563,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L12527-L12563","documentation":"CImgDisplay::render(const CImg<T>&) throws CImgArgumentException when the source image is empty. Rendering requires valid pixel data to copy into the display buffer; an empty image has none. Note render() also silently returns if the display itself is empty, so this exception specifically signals an empty image argument.","triggerScenarios":"Calling render(img) directly, or indirectly via display(img) on a non-empty display, with an img whose _width/_height are 0.","commonSituations":"Rendering frames in a loop where a decode step failed on some iteration; passing a cropped sub-image that ended up zero-sized; using an image constructed with CImg(w=0,h=0).","solutions":["Guard the render call with if (img) render(img).","Verify the image producer (load, crop, append) returned a non-empty image each frame.","If the display may also be empty, prefer display(img) which handles empty displays via assign(img)."],"exampleFix":"// before\nfor (...) disp.render(frames[i]); // throws on failed decode\n// after\nif (frames[i]) disp.render(frames[i]); else disp.paint();","handlingStrategy":"validation","validationCode":"if (img && !disp.is_empty()) disp.render(img).paint();","typeGuard":"bool renderable(const cimg_library::CImg<T>& img, const cimg_library::CImgDisplay& d) { return (bool)img && !d.is_empty(); }","tryCatchPattern":"try { disp.render(img); }\ncatch (cimg_library::CImgArgumentException &e) { fprintf(stderr, \"%s\", e.what()); }","preventionTips":["Check img truthiness every frame in render loops.","Ensure decode/crop steps report failures instead of emitting empty images.","Prefer display() over render() when the display lifecycle is not fully controlled."],"tags":["cimg","empty-image","argument-validation"],"backgroundTag":"empty-required-field","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}