AviSynth / AviSynthPlus

AviSynth with improvements
http://avs-plus.net
963 stars 73 forks source link

HistogramRGBParade script crash #360

Closed DTL2020 closed 1 year ago

DTL2020 commented 1 year ago

Script functions from http://avisynth.nl/images/Histograms_in_RGB_%26_CMY.avsi

Checked with 3.6.1 (release ?) and 3.7.3. test 7:

function HistogramRGBLevels( clip input, bool "range", float "factor" ) { return HistogramRGBLevelsType( input, input.ConvertToRGB(), $800000, $008000, $000080, range, factor ) }

function HistogramCMYLevels( clip input, bool "range", float "factor" ) { return HistogramRGBLevelsType( input, input.ConvertToRGB().Invert(), $008080, $800080, $808000, range, factor ) }

function HistogramRGBParade( clip input, float "width" ) { return HistogramRGBParadeType( input, input.ConvertToRGB(), $800000, $008000, $000080, width ) }

---

Generic levels form, not very useful as a standalone function

function HistogramRGBLevelsType( clip input, clip rgb, int color1, int color2, int color3, bool "range", float "factor" ) { range = default(range,true) ChannelHeight = 64 Gap = 8 # divisible by 4

r = rgb.ShowRed  ("YV12").HistogramChannel("Levels", color1, "add", ChannelHeight, range, factor)
g = rgb.ShowGreen("YV12").HistogramChannel("Levels", color2, "add", ChannelHeight, range, factor)
b = rgb.ShowBlue ("YV12").HistogramChannel("Levels", color3, "add", ChannelHeight, range, factor)
gap = BlankClip(r, height=Gap)
hist = StackVertical(r,gap,g,gap,b).ConvertToMatch(input)
return input.Height() > hist.Height() ? \ 
       StackHorizontal(input, hist.AddBorders(0,0,0,input.Height() - hist.Height())) : \
       StackHorizontal(input.AddBorders(0,0,0,hist.Height() - input.Height()), hist)

}

Generic parade form, not very useful as a standalone function

function HistogramRGBParadeType( clip input, clip rgb, int color1, int color2, int color3, float "width" ) { width = default(width,0.25) Gap = 8 # divisible by 4

rgb = rgb.PointResize( m4(rgb.Width()*width), m4(rgb.Height()) ).TurnRight()
r = rgb.ShowRed  ("YV12").HistogramChannel("Classic", color1, "chroma", 0, true)
g = rgb.ShowGreen("YV12").HistogramChannel("Classic", color2, "chroma", 0, true)
b = rgb.ShowBlue ("YV12").HistogramChannel("Classic", color3, "chroma", 0, true)
gap = BlankClip(r, height=Gap)
hist = StackVertical(r,gap,g,gap,b).TurnLeft().ConvertToMatch(input)
return input.Height() > hist.Height() ? \ 
       StackHorizontal(input, hist.AddBorders(0,0,0,input.Height() - hist.Height())) : \
       StackHorizontal(input.AddBorders(0,0,0,hist.Height() - input.Height()), hist)

}

Used by functions above, not a standalone function

function HistogramChannel( clip input, string type, int color, string colorMode, int height, bool range, float "factor" ) { input.Histogram(type, factor).Crop(input.Width(),0,0,height).Greyscale() range ? last : Levels(128,1.0,255,0,255,false) return Overlay(BlankClip(color=color), mode=colorMode) }

Returns "input" converted to same colorspace as "ref"

function ConvertToMatch( clip input, clip ref ) { return ref.IsYV12() ? input.IsYV12() ? input : input.ConvertToYV12() : \ ref.IsRGB32() ? input.IsRGB32() ? input : input.ConvertToRGB32() : \ ref.IsRGB24() ? input.IsRGB24() ? input : input.ConvertToRGB24() : \ ref.IsYUY2() ? input.IsYUY2() ? input : input.ConvertToYUY2() : \ ref.IsYV16() ? input.IsYV16() ? input : input.ConvertToYV16() : \ ref.IsYV24() ? input.IsYV24() ? input : input.ConvertToYV24() : \ ref.IsY8() ? input.IsY8() ? input : input.ConvertToY8() : \ ref.IsYV411() ? input.IsYV411() ? input : input.ConvertToYV411() : \ input }

Convert value to multiple of 4 which is >= 16

function m4( float x ) { return (x < 16 ? 16 : int(round(x / 4.0) * 4)) }

BlankClip(length=1, width=256, height=256, pixel_type="Y8")

ConvertToRGB32()

HistogramRGBParade()

Crash both VirtualDub and AVSmeter. The debugger with VirtualDub shows output: Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079CFC0. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079CFC0. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079CFC0. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079CFC0. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079D230. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079D230. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079D230. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079D230. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079D230. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFA5458CF19 in VirtualDub64.exe: Microsoft C++ exception: ReturnExprException at memory location 0x000000000079D230. Critical error detected c0000374 VirtualDub64.exe has triggered a breakpoint.

DTL2020 commented 1 year ago

Also poisondeathray report - I believe the crash is dimension related (width, height) No crash if you resize to 640x480, preview , then change to 512x512. But it only works after you run a script first that works (this is in avspmod) . If you start with 512x512, it crashes

DTL2020 commented 1 year ago

StainlessS -

Windows Logs/Application: 0xc0000374, Heap Corruption.

Code:

Faulting application name: VirtualDub64.exe, version: 2.0.0.0, time stamp: 0x5e73f48a Faulting module name: ntdll.dll, version: 10.0.19041.2788, time stamp: 0x2f715b17 Exception code: 0xc0000374 Fault offset: 0x00000000000ff449 Faulting process ID: 0x24f4 Faulting application start time: 0x01d99680ff1cb793 Faulting application path: C:\NON-INSTALL\VDUB\VDUB2\VirtualDub64.exe Faulting module path: C:\WINDOWS\SYSTEM32\ntdll.dll Report ID: 3170e74f-582d-40e8-891b-0847f484c03c

Heap corruption may be detected by some check in ntdll.dll but the source of corruption may be in either AVS or calling application module ?

pinterf commented 1 year ago

Thanks, this kind of bug is probably easy to reproduce and resolve, I'm gonna check it soon.

DTL2020 commented 1 year ago

Yes - the size 256x256 with HistogramRGBParade(width=1.0) work now. Thank you.