I am facing some kind of issues that I am having difficulties to solve. I am
getting the following error during runtime:
Traceback (most recent call last)
/home/jose/src/VapourSynth.nim/src/filters/modifyframe.nim(9) modifyframe
/home/jose/src/VapourSynth.nim/src/output.nim(115) Savey4m
/home/jose/src/VapourSynth.nim/src/output.nim(83) writeY4mFrames
/home/jose/src/VapourSynth.nim/src/vsframe.nim(114) getFrame
/home/jose/src/VapourSynth.nim/src/filters/DrawFrame.nim(24)
DrawFrameGetFrame
/home/jose/src/VapourSynth.nim/src/filters/kernel.nim(12) apply_kernel
/home/jose/src/VapourSynth.nim/src/vsframe.nim(184) []
/home/jose/src/VapourSynth.nim/src/vsframe.nim(166) getPlane
/home/jose/.choosenim/toolchains/nim-1.0.6/lib/system/gc.nim(439) newObj
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
The function that is failing is the following:
proc getPlane*(frame:ptr VSFrameRef, plane:Natural):Plane =
if frame == nil:
raise newException(ValueError, "called with nil pointer")
let frameFormat = getFrameFormat(frame)
#echo "FRAME FORMAT------------> ", repr frameFormat
#echo frameFormat.bytesPerSample
#let format = frameFormat.toFormat
if plane > frameFormat.numPlanes-1:
raise newException(ValueError, "the plane requested is above the number
of planes available")
let width = getFrameWidth( frame, plane )
let height = getFrameHeight( frame, plane )
let stride = getStride(frame, plane )
let planeptr = getReadPtr(frame, plane) # Plane pointer
let planeptrW = getWritePtr(frame, plane)
let ssW = if plane > 0: frameFormat.subSamplingW else: 0
let ssH = if plane > 0: frameFormat.subSamplingH else: 0
let bytesPerSample = frameFormat.bytesPerSample.int
# TODO: to deal with bigger bytes per sample
var rowPointers:seq[ptr UncheckedArray[uint8]]
newSeq(rowPointers, height)
let ini = cast[int](planeptrW)
#echo "INI: ", ini, " STRIDE: ", stride
for row in 0..<height:
#echo " value: ", ini + row*stride
rowPointers[row] = cast[ptr UncheckedArray[uint8]]( ini + row * stride )
#echo " row: ", row
echo "ok"
echo &"Width: {width} bytesPerSample: {bytesPerSample} "
#echo bytesPerSample
let rowSize = width * bytesPerSample
Plane( width:width,
height:height,
idx:plane,
ptrIniRead:planeptr,
ptrCurRead:planeptr,
ptrIniWrite:planeptrW,
ptrCurWrite:planeptrW,
rowSize: rowSize,
stride:stride,
subSamplingW:ssW,
subSamplingH:ssH,
bytesPerSample: bytesPerSample,
rows:rowPointers )
Run
The function works fine, but after some time it fails when I first use width:
echo &"Width: {width} bytesPerSample: {bytesPerSample} "
Run
surprisingly it doesn't fail when I do:
let width = getFrameWidth( frame, plane )
Run
Just for information, getFrameWidth is defined as:
proc getFrameWidth*(frame:ptr VSFrameRef, plane:int):int =
## Returns the width of a plane of a given frame, in pixels. The width
depends on the plane number because of the possible chroma subsampling.
return API.getFrameWidth(frame, plane.cint).int
Run
which calls a C function defined as:
type
VSAPI* {.bycopy.} = object
....
getFrameWidth*: proc (f: ptr VSFrameRef; plane: cint): cint {.cdecl.}
....
Run
(this struct defines the VapourSynth's API; defined by means of c2nim)
Any clue about what I can do?