Skip to content

Commit 2635e4b

Browse files
committed
try fix segfault in sdcpp
1 parent 485148b commit 2635e4b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,11 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
521521
int img2imgW = sd_params->width; //for img2img input
522522
int img2imgH = sd_params->height;
523523
int img2imgC = 3; // Assuming RGB image
524-
std::vector<uint8_t> resized_image_buf(img2imgW * img2imgH * img2imgC);
525-
std::vector<uint8_t> resized_mask_buf(img2imgW * img2imgH * img2imgC);
526-
std::vector<std::vector<uint8_t>> resized_extraimage_bufs(max_extra_images, std::vector<uint8_t>(img2imgW * img2imgH * img2imgC));
524+
//because the reference image can be larger than the output image, allocate at least enough for 1024x1024
525+
const int imgMemNeed = std::max(img2imgW * img2imgH * img2imgC + 512, 1024 * 1024 * img2imgC + 512);
526+
std::vector<uint8_t> resized_image_buf(imgMemNeed);
527+
std::vector<uint8_t> resized_mask_buf(imgMemNeed);
528+
std::vector<std::vector<uint8_t>> resized_extraimage_bufs(max_extra_images, std::vector<uint8_t>(imgMemNeed));
527529

528530
std::string ts = get_timestamp_str();
529531
if(!sd_is_quiet)
@@ -623,6 +625,18 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
623625
}
624626
}
625627

628+
//round dims down to 64
629+
desiredWidth = rounddown_64(desiredWidth);
630+
desiredHeight = rounddown_64(desiredHeight);
631+
if(desiredWidth<64)
632+
{
633+
desiredWidth = 64;
634+
}
635+
if(desiredHeight<64)
636+
{
637+
desiredHeight = 64;
638+
}
639+
626640
if(!sd_is_quiet && sddebugmode==1)
627641
{
628642
printf("Resize Extraimg: %dx%d to %dx%d\n",nx2,ny2,desiredWidth,desiredHeight);

0 commit comments

Comments
 (0)