Lightroom 5 SDK: catalog:getActiveSources() throws an error if called too soon during startup.

  • 2
  • Problem
  • Updated 4 years ago
Work-around:

dbgf( "getting active sources" )
local srcs
for try = 1, 5 do
local sts
sts, srcs = LrTasks.pcall( catalog.getActiveSources, catalog ) -- assertion failed error when called upon Lr startup, hmm...
dbgf( "returned from getting active sources (try ^1), sts: ^2", try, sts )
if sts then break end
app:sleep( timebase )
if shutdown then return end
end
if not tab:isArray( srcs ) then
app:logW( "No photo sources." )
return
end
dbgf( "got active sources, disabling filter" )

i.e. call catalog.getActiveSources in protected fashion, and retry upon failure.
Note: this has been 100% repeatable so far.
win7/64
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes

Posted 5 years ago

  • 2
Photo of John R. Ellis

John R. Ellis, Champion

  • 3712 Posts
  • 971 Reply Likes
I too have encountered this -- thanks for submitting. Here's a code fragment I have from my Any Source plugin:

LrTasks.sleep (5)
--[[ We can't call catalog:getActiveSources() until LR is
fully started -- otherwise, we get assertion failed. ]]
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
Thanks for confirming John.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
I think this function returns an empty array during startup on Mac, instead of throwing an error like it does in Windows.

Again: regardless of how it works (or when it doesn't), it should be:
* the same on both systems, preferrably.
* whether the same or not: anomalous (or different) behavior should be documented.

Rob