You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The lua function lens.focus(), when called with continuous autofocus enabled will trigger a lua error that cannot be properly handled. A lua error draw the console and print a large error. I provided an example of what a lua error looks like. It can be annoying in LiveView.
Workaround
It is possible to use the function pcall that act as a try {} catch() {}. However this is considered bad practice and is slow. An example is provided in the Reproducing section.
Reproducing
Run the following script in LiveView with AutoFocus and ContinuousAF enabled then press half shutter + up arrow to trigger the error.
diff --git a/modules/lua/lua_lens.c b/modules/lua/lua_lens.c
index d2ae5dc54..5f54fb462 100644
--- a/modules/lua/lua_lens.c+++ b/modules/lua/lua_lens.c@@ -122,7 +122,7 @@ static int luaCB_lens_focus(lua_State * L)
if (!lv) return luaL_error(L, "lens.focus() only works in LiveView.");
if (is_manual_focus()) return luaL_error(L, "lens.focus() requires autofocus enabled.");
- if (is_continuous_af()) return luaL_error(L, "lens.focus() requires %s AF disabled.", is_movie_mode() ? "movie servo" : "continuous");+ //if (is_continuous_af()) return luaL_error(L, "lens.focus() requires %s AF disabled.", is_movie_mode() ? "movie servo" : "continuous");
lua_pushboolean(L, lens_focus(num_steps, step_size, wait, delay));
diff --git a/src/lens.c b/src/lens.c
index e56b552ec..6733a2b9f 100644
--- a/src/lens.c+++ b/src/lens.c@@ -677,7 +677,7 @@ lens_focus(
if (!lv) return 0;
if (is_manual_focus()) return 0;
- if (is_continuous_af()) return 0;+ //if (is_continuous_af()) return 0;
if (num_steps < 0)
{
Removing these line does work on my device. lens_focus can work even with continuous_af enabled
I'm daily driving a Canon 100D on commit 8c1a327
If this patch cannot be applied on every device, then this Pull Request #122 is still relevant
The text was updated successfully, but these errors were encountered:
I don't know Lua well at all. I've done a little reading and some benchmarking.
When you say "will trigger a lua error that cannot be properly handled" - can this in fact be handled by pcall()? Are you referring to the potential speed cost when you say it can't be done properly?
I benchmarked pcall (on desktop, not cam). While pcall is noticeably slower than a normal call (about 10x), I can still do 50 million pcalls in 12s. I was using a minimal function, whereas here we have lens.focus, which will do more work, so the overhead of pcall will be less. Your code is doing key press handling, so cannot be rapidly called repeatedly.
I don't see any concerning cost to pcall, and it seems to me that this is precisely the circumstance where using pcall is appropriate: an external API can error, pcall allows you to handle this without needing to modify code outside of your domain (that is: modify ML code to allow a user script to work).
As I say, I don't know Lua well, so please let me know if I've misunderstood something or have something incorrect.
Hello,
Issue
The lua function lens.focus(), when called with continuous autofocus enabled will trigger a lua error that cannot be properly handled. A lua error draw the console and print a large error. I provided an example of what a lua error looks like. It can be annoying in LiveView.
Workaround
It is possible to use the function pcall that act as a try {} catch() {}. However this is considered bad practice and is slow. An example is provided in the Reproducing section.
Reproducing
Run the following script in LiveView with AutoFocus and ContinuousAF enabled then press half shutter + up arrow to trigger the error.
ML/scripts/focus.lua
Potential patch
Removing these line does work on my device. lens_focus can work even with continuous_af enabled
I'm daily driving a Canon 100D on commit 8c1a327
If this patch cannot be applied on every device, then this Pull Request #122 is still relevant
The text was updated successfully, but these errors were encountered: