Skip to content

fix: lazy initialize ImageRegistry#1011

Merged
sebthom merged 1 commit into
eclipse-tm4e:mainfrom
trancexpress:gh1010
Jul 2, 2026
Merged

fix: lazy initialize ImageRegistry#1011
sebthom merged 1 commit into
eclipse-tm4e:mainfrom
trancexpress:gh1010

Conversation

@trancexpress

@trancexpress trancexpress commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This change adjusts TMUIPlugin.start() to not initialize the ImageRegistry, avoiding start-up exceptions when TMUIPlugin.start() is not called from a UI thread.

Instead, the ImageRegistry is initialized lazily by overriding: AbstractUIPlugin.initializeImageRegistry()

Fixes: #1010

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates TMUIPlugin.start() to avoid SWTError: Invalid thread access by deferring image-registry initialization to the UI thread when the Eclipse workbench is running (addressing issue #1010 seen in headless/LSP test scenarios).

Changes:

  • Replace direct image initialization in TMUIPlugin.start() with a dedicated initializeImages() helper.
  • Schedule TMImages initialization via an Eclipse UIJob when PlatformUI.isWorkbenchRunning() is true.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java Outdated
Comment thread org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/TMUIPlugin.java Outdated
@sebthom

sebthom commented Jun 12, 2026

Copy link
Copy Markdown
Member

@akurtakov do you think a more idomatic solution would be to not initialize the image registry in the start method or async via UIJob but lazy like this?

 @Override
 protected void initializeImageRegistry(final ImageRegistry registry) {
      TMImages.initalize(registry);
  }

@sebthom

sebthom commented Jun 30, 2026

Copy link
Copy Markdown
Member

@akurtakov ping :-)

@akurtakov

Copy link
Copy Markdown
Contributor

@sebthom Sorry, this one got lost in the amount of notifications.
Your suggestion should be the way to go IMO, that should solve the problem as createImageRegistry already falls back to Display.getCurrent if platform is not running https://github.com/eclipse-platform/eclipse.platform.ui/blob/a217bfc2419673f6547fb67f0970cbf91bdf2192/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/plugin/AbstractUIPlugin.java#L160 .

This change adjusts TMUIPlugin.start() to not initialize the ImageRegistry,
avoiding start-up exceptions when TMUIPlugin.start() is not called from a UI thread.

Instead, the ImageRegistry is initialized lazily by overriding:
AbstractUIPlugin.initializeImageRegistry()

Fixes: eclipse-tm4e#1010
@trancexpress trancexpress changed the title fix: initialize images in a UI job if workbench is running fix: lazy initialize ImageRegistry Jul 1, 2026
@sebthom sebthom merged commit 6314a5e into eclipse-tm4e:main Jul 2, 2026
23 checks passed
@sebthom

sebthom commented Jul 2, 2026

Copy link
Copy Markdown
Member

Thanks!

@trancexpress

Copy link
Copy Markdown
Contributor Author

Thank you for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TMUIPlugin.start() throws SWTError when not called from UI thread

6 participants