Skip to main content
rolandp92181609
Participant
November 9, 2024

P: Problem with LrView:combo_box and binding for items

  • November 9, 2024
  • 3 replies
  • 517 views

Hello,

I try to use a combo_box with a binding for the items:

 

 

local function main()
  LrFunctionContext.callWithContext('showDialog', function(context)

    local props = LrBinding.makePropertyTable( context )
    props.items = { '1', '2', '3'}
    props.value = ''

    logDebug('main', '#Items = ' .. #props.items ) 
    
    local f = LrView.osFactory()
    local view = f:column {
      bind_to_object = props,
      f:row{ 
        f:combo_box{ items = LrView.bind('items'), value = LrView.bind('value'), width = 50 },  
        f:push_button{ 
          title = 'Remove',
          action = function()
            if #props.items > 1 then table.remove(props.items, #props.items ) end
            logDebug('main', 'After remove #Items = ' .. #props.items ) 
          end,
        }, 
      },
    }    
  
    status = LrDialogs.presentModalDialog {
      title = 'test combo box',
      contents = view,
    }      
  end )
end

 

 

Initially all three items are displayed. By pressing the 'Remove' button the last item is removed from the item table, but still all three items are displayed. After selecting the last (non-existing) item Lightroom crashes.

 

Any ideas what's the code?

 

Regards. Roland

3 replies

Rikk Flohr_Photography
Community Manager
November 11, 2024

Updating Status - Adding Bug Number

Rikk Flohr: Adobe Photography Org
johnrellis
Legend
November 9, 2024

Removing an item from the array of items of a viewFactory:combo_box() can crash LR 14.0.1 on Windows 11 (but not Mac OS 15). To reproduce:

 

1. Save the script below to the file "combo_box-bug.lua" in the Lightroom settings Scripts folder and restart LR.

 

2. Do Scripts > combo_box-bug.

 

3. Click on the combo box's dropdown and observe two items. Don't select either item:

 

4. Click Remove. 

 

5. Click on the dropdown and select item "2".  In a few seconds LR will crash (incorrect). I've submitted a crash report under my Adobe Id.

 

I've posted above a fix to the code for correctly removing an item from a combo box. But plugins should never be able to crash LR.

 

local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
local bind = LrView.bind
local f = LrView.osFactory ()

LrFunctionContext.callWithContext ("Test", function (context)
    local prop = LrBinding.makePropertyTable (context, context)
    prop.items = {1, 2}
    prop.value = ""

    LrDialogs.presentModalDialog {title = "combo_box bug", contents = f:row {
        bind_to_object = prop,
        f:combo_box {items = bind "items", value = bind "value", width = 100},  
        f:push_button {title = "Remove",  action = function ()
            table.remove (prop.items, #prop.items) end}}}
    end)

 

johnrellis
Legend
November 9, 2024

@Rikk Flohr: Photography, I posted above a simple recipe for reliably crashing LR and submitted a crash report under my Adobe Id. Please move to Bugs, thanks.

johnrellis
Legend
November 9, 2024

LR should never crash -- I'll start a bug report.

 

The issue with your code is that observable tables (LrObservableTable) only observe assignments to the key values themselves. If a key value is a table, they don't notice changes to the contents of that table.

 

The fix for your code is easy. After the call to table.remove(), add this line:

props.items = props.items

The assignment to the key "items" will be observed, and the combo_box() will get updated appropriately.

rolandp92181609
Participant
November 9, 2024

Thanks!! After the simple change it works.

With your explanations it is clear why it didn't work before.

 

Thanks Roland

 

PS: I also submit an bug report via the Lightroom popup message.