Skip to content

[Bug] [example] Crash caused by discarded ‘preview_path’ pointer #994

@masamaru-san

Description

@masamaru-san

Git commit

[11/21 13:56:37] PS E:\stable-diffusion.cpp
> git rev-parse HEAD
5498cc0d67b0f95b4ef6004890b18cdbe3678175

Operating System & Version

Windows 11 25H2 [Version 10.0.26200.7171]

GGML backends

Vulkan

Command-line arguments used

see reproduce section

Steps to reproduce

I encountered crashes while testing t2v using ‘Wan2.2-TI2V-5B’. The running script is below:

# Run.ps1
[string]$prompt  = 'Wind-swaying dandelion in a meadow, floating in a gentle breeze, bright sunlight, natural setting, vibrant colors, 4k, photorealistic, high detail, warm tones, cinematic lighting, high quality
'
[string]$nprompt = 'no clutter, no black, too much blur'

[string]$sd_path = 'E:\stable-diffusion.cpp\out\build\x64-RelWDeb-ClangCL\bin\sd.exe'

. $sd_path `
	-M vid_gen `
	--diffusion-model 'E:\AI\models\wan\Wan2.2-TI2V-5B-Q4_K_M.gguf' `
	--vae             'E:\AI\models\wan\wan2.2_vae.safetensors' `
	--t5xxl           'E:\AI\models\wan\umt5-xxl-encoder-Q4_K_S.gguf' `
	-p $prompt --negative-prompt $nprompt `
	--cfg-scale 6.0 --sampling-method euler -v -t 14 --diffusion-conv-direct --vae-conv-direct `
	--color -W 832 -H 480 --diffusion-fa --video-frames 33 --flow-shift 3.0 --offload-to-cpu --clip-on-cpu -o ".\out_$([datetime]::Now.ToString('yyMMdd_hhmm')).avi"
> & Run.ps1

What you expected to happen

No crashes, except those caused by backend or hardware issues...

What actually happened

Crash silently (and launches MSVC debugger). Changing the compiler or modifying parts of the code sometimes prevents the crash.

The debugger showed that the issue was due to the base_path object that was passed to the preview_path pointer being destroyed (inaccessible).

std::string base_path = params.preview_path;
std::string file_ext = "";
if (last_dot_pos != std::string::npos) { // filename has extension
base_path = params.preview_path.substr(0, last_dot_pos);
file_ext = params.preview_path.substr(last_dot_pos);
std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), ::tolower);
}
if (file_ext == ".png") {
base_path = base_path + ".avi";
preview_path = base_path.c_str();
}

It seems that changing the variable preview_path from const char* to a std::string object, and modifying related lines, allowed us to avoid the crash.

Logs / error messages / stack trace

silently crashed without any messages in console.

Additional context / environment details

> clang-cl --version
clang version 20.1.8
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\Llvm\x64\bin

> cl
Microsoft(R) C/C++ Optimizing Compiler Version 19.50.35718 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions