pcall() considered harmful
|Opened on:||Wednesday, April 5, 2017 - 07:32|
|Last modified:||Sunday, February 23, 2020 - 20:52|
The pcall function is built in to Lua. It's intended to catch errors. A Foldit recipe can use pcall to trap errors that would otherwise terminate the recipe.
The following Lua code now crashes the client:
for ii = 1, 9999 do print ( "test # " .. ii ) pcall ( selection.SelectRange, -1, 9999 ) end
This command does not crash the client:
selection.SelectRange ( -1, 9999 )
Also, this version does not cause a crash:
for ii = 1, 9999 do print ( "test # " .. ii ) pcall ( selection.SelectRange, 1, 10 ) end
So it seems to have something to do with a Foldit function, called via pcall, that throws an error.
This is somewhat new behavior. I have test script that checks around 100 boundary conditions. I hadn't run the script since September 2015, but it was working at the time. Now it crashes somewhat consistently after about 75 pcalls, not all of which are expected to produce an error.
The loop example above causes a crash much more quickly, although it's hard to tell exactly how many tests it completes.