try fix segfault in sdcpp

This commit is contained in:
Concedo 2025-06-29 02:33:03 +08:00
parent 485148b293
commit 2635e4b932

View file

@ -521,9 +521,11 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
int img2imgW = sd_params->width; //for img2img input int img2imgW = sd_params->width; //for img2img input
int img2imgH = sd_params->height; int img2imgH = sd_params->height;
int img2imgC = 3; // Assuming RGB image int img2imgC = 3; // Assuming RGB image
std::vector<uint8_t> resized_image_buf(img2imgW * img2imgH * img2imgC); //because the reference image can be larger than the output image, allocate at least enough for 1024x1024
std::vector<uint8_t> resized_mask_buf(img2imgW * img2imgH * img2imgC); const int imgMemNeed = std::max(img2imgW * img2imgH * img2imgC + 512, 1024 * 1024 * img2imgC + 512);
std::vector<std::vector<uint8_t>> resized_extraimage_bufs(max_extra_images, std::vector<uint8_t>(img2imgW * img2imgH * img2imgC)); std::vector<uint8_t> resized_image_buf(imgMemNeed);
std::vector<uint8_t> resized_mask_buf(imgMemNeed);
std::vector<std::vector<uint8_t>> resized_extraimage_bufs(max_extra_images, std::vector<uint8_t>(imgMemNeed));
std::string ts = get_timestamp_str(); std::string ts = get_timestamp_str();
if(!sd_is_quiet) if(!sd_is_quiet)
@ -623,6 +625,18 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
} }
} }
//round dims down to 64
desiredWidth = rounddown_64(desiredWidth);
desiredHeight = rounddown_64(desiredHeight);
if(desiredWidth<64)
{
desiredWidth = 64;
}
if(desiredHeight<64)
{
desiredHeight = 64;
}
if(!sd_is_quiet && sddebugmode==1) if(!sd_is_quiet && sddebugmode==1)
{ {
printf("Resize Extraimg: %dx%d to %dx%d\n",nx2,ny2,desiredWidth,desiredHeight); printf("Resize Extraimg: %dx%d to %dx%d\n",nx2,ny2,desiredWidth,desiredHeight);