Skip to content
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

PopUpMenu.item throws errors if item list is empty #6503

Open
daveriedstra opened this issue Oct 7, 2024 · 2 comments
Open

PopUpMenu.item throws errors if item list is empty #6503

daveriedstra opened this issue Oct 7, 2024 · 2 comments
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead

Comments

@daveriedstra
Copy link

Attempting to access an item from PopUpMenu will fail with an error if the item list is either non-instantiated or empty. The error message is the same as attempting to access an element of an non-instantiated or empty collection, which makes debugging difficult and time-consuming. This can come up when the menu item list is automatically populated and there is a chance it could be empty (in my case, selecting a hardware peripheral).

Environment

  • SuperCollider version: 3.11.2
  • Operating system: Linux (Pop!_OS 22.04)

Steps to reproduce

m = PopUpMenu();
m.item.postln; // fails with "Message 'at' not understood"
m.items = [];
m.item.postln; // fails with "Primitive '_BasicAt' failed."

Expected vs. actual behavior

Expected: return nil with no error or fail with a more informative error
Actual: misleading error

@daveriedstra daveriedstra added the bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. label Oct 7, 2024
@capital-G capital-G added comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead comp: class library SC class library labels Oct 8, 2024
@capital-G
Copy link
Contributor

Could be fixed by overwriting the item getter in the PopUpMenu class, so something along

	item {
		^if(this.value.isNil, {
			nil
		}, {
			items.at( this.value )
		});
	}

Do you want to make a PR, @daveriedstra ?

@daveriedstra
Copy link
Author

I'd be glad to! It might be a while before I have the time though, so if someone else gets to it first that's fine too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead
Projects
None yet
Development

No branches or pull requests

2 participants