-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Program crashes when calling ctx.stroke() even when wrapped in try #388
Comments
If you can give us a stand alone example we can run that would be great. When I run this, nothing crashes: import pixie
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
let ctx = newContext(image)
echo "GStroke"
echo "StrokeStyle: ", ctx.strokeStyle.repr
try:
ctx.stroke()
except:
echo getCurrentExceptionMsg()
raise
image.writeFile("crashStroke.png") Please provide a better example and we will fix it. |
Here is even a better example that replicates your stroke style, still no crash: import pixie
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
let ctx = newContext(image)
ctx.beginPath()
ctx.moveTo(75, 50)
ctx.lineTo(100, 75)
ctx.lineTo(100, 25)
ctx.lineWidth = 10
ctx.strokeStyle = Paint(
kind: AngularGradientPaint,
blendMode: NormalBlend,
opacity: 0.2196078449487686,
color: color(0.2156862765550613, 0.0, 0.007843137718737125, 0.2196078449487686),
image: newImage(1, 1),
imageMat: mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0),
gradientHandlePositions: @[vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, 0.0)],
gradientStops: @[ColorStop(color: color(0.0, 0.0, 0.0, 0.0), position: 0.0)]
)
echo "GStroke"
echo "StrokeStyle: ", ctx.strokeStyle.repr
try:
ctx.stroke()
except:
echo getCurrentExceptionMsg()
raise
image.writeFile("crashStroke.png")``` |
I added code to my program to make it write the nim statements that were being executed. So here is a relatively short program that illustrates the problem. It never returns from ctx.StrokePolygon. I'm not sure exactly why it fails on that instead of at ctx.Stroke now but it's probably because I commented out some code in a vain attempt to isolate the problem.
It is the operating system that is killing the program. It reached 99% CPU, 69.6% memory before htop and everything else stopped responding. |
Thanks! I see the bug now. That was hardly a simple example here is the same crash, but with all not needed lines removed: import pixie
let image = newImage(200, 200)
let ctx = newContext(image)
ctx.setLineDash(@[0.0.float32])
ctx.strokePolygon(vec2(100.0, 100.0), 50.0, 3) The problem is |
Fixed, now it will throw an exception when this happens. Should be in the next release, you can get it from source or just don't set line dash to 0. |
Got it.
if the argument tosetLineDash contains only zeroes then strokePolygon never completes and uses all available memory. I think it must be in the pixie/paths.nim strokePaths proc that the infinite loops occurs:
I can easily check for this condition in my code but perhaps pixie should too. |
It probably doesn't matter but it seems to me that your fix is stricter than necessary.
|
I'm using pixie.Context to experiment with some semi-random drawing.
I build strokeStyle and path and then execute ctx.stroke. The program crashes even if I wrap the ctx.stroke call in a try.
I daresay that the strokeStyle is the culprit but it should surely not kill the program.
the snippet of code looks like this:
And this is the result:
I can try to create a stand alone example if necessary.
Edit: I've hardcoded the paint kind to SolidPaint so presumably it is not the strokeStyle that is the problem after all, perhaps it is the path.
The text was updated successfully, but these errors were encountered: