Re: Strange (maybe memory related behaviour)

2020-03-30 Thread Araq
Maybe you need to call `setupForeignThreadGC` in your loop if it's called from 
C.


Re: Strange (maybe memory related behaviour)

2020-03-29 Thread moerm
The echo statement might trigger a call to getFrameWidth().

Try to do an "old style" echo like 'echo "Width: " & $width' directly after a 
getFrameWidth() call and assigning its result ("let width = 
getFrameWidth(...)". 


Re: Strange (maybe memory related behaviour)

2020-03-29 Thread Stefan_Salewski
I don't think that your problem is in some way related to the echo statement -- 
echo may in this case only trigger the bug, maybe because due to echo new 
memory is allocated or freed.

Such types of bugs are very hard.


Re: Strange (maybe memory related behaviour)

2020-03-29 Thread mantielero
What I have done is to go for a minimal execution trying to find problems. 
Something strange that I have observed while doing so is that if I comment the 
line:


echo &"Width: {width}   bytesPerSample: {bytesPerSample} "

Run

I pass from 369 errors in 61 contexts to 0. Why could that be?


Re: Strange (maybe memory related behaviour)

2020-03-29 Thread mantielero
Thanks Stefan.

So:


nim c -r modifyframe

fails after 6 frames as explained before.

arc fails for me:


$ nim c --gc:arc modifyframe
Hint: used config file 
'/home/jose/.choosenim/toolchains/nim-1.0.6/config/nim.cfg' [Conf]
command line(1, 2) Error: 'none', 'boehm' or 'refc' expected, but 'arc' 
found

With valgrind (first time using it) takes me a bit further (14 frames). I 
pasted the outcome [here](https://pastebin.com/YbbnmzBv).

If I activate more flags I get this .

I don't know what to do with that information :O/.


Re: Strange (maybe memory related behaviour)

2020-03-29 Thread Stefan_Salewski
Ah yes, arc is available in devel. But try --gc:none, maybe also boehm.

Of course that will not really help, the bug is not Nim GC but your bindings, 
but maybe it gives somehow more insight.

I think valgrind does only help with --gc:arc and -d:useMalloc.


Re: Strange (maybe memory related behaviour)

2020-03-29 Thread Stefan_Salewski
> The function works fine, but after some time it fails

Are you using default refc GC or new --gc:arc?

I assume default refc. In that case I would assume that there is something 
wrong in your bindings, so when the GC starts for the first time it fails. You 
may call GC_Fullcollect() early, then the bug may occur earlier.

And you can try too compile with --gc:arc -d:useMalloc, then you have a more 
deterministic GC and the error may come earlier. In this case you can also try 
running your app by valgrind, valgrind may tell you details.

You can also play with --gc:none, maybe then your app runs longer, until all 
memory is consumed.

That are the first steps I would try...


Strange (maybe memory related behaviour)

2020-03-29 Thread mantielero
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..