Skip to content

Commit

Permalink
Fix widget is disposed error during shutdown (#51)
Browse files Browse the repository at this point in the history
After building a project and shuting down eclipse, the build console
will have a propertyChange event fired that will attempt to modify the
stream and background color that will trigger a use-after-dispose error
from SWT. This changeset ensures that the action is only taken on
non-disposed widgets.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
  • Loading branch information
Torbjorn-Svensson committed Aug 22, 2022
1 parent 6e5840d commit 5039ad3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true
Bundle-Version: 7.3.300.qualifier
Bundle-Version: 7.3.301.qualifier
Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Expand Up @@ -249,18 +249,28 @@ public void propertyChange(PropertyChangeEvent event) {

if (BuildConsole.P_STREAM_COLOR.equals(property) && source instanceof IBuildConsoleStreamDecorator) {
IBuildConsoleStreamDecorator stream = (IBuildConsoleStreamDecorator) source;
if (stream.getConsole().equals(getConsole()) && getControl() != null) {
Display display = getControl().getDisplay();
display.asyncExec(() -> getViewer().getTextWidget().redraw());
if (stream.getConsole().equals(getConsole())) {
Control control = getControl();
if (control != null && !control.isDisposed()) {
control.getDisplay().asyncExec(() -> {
StyledText textWidget = getViewer().getTextWidget();
if (textWidget != null && !textWidget.isDisposed()) {
textWidget.redraw();
}
});
}
}
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)) {
setFont(JFaceResources.getFont(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT));
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH)) {
setTabs(CUIPlugin.getDefault().getPreferenceStore()
.getInt(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH));
} else if (IConsoleConstants.P_BACKGROUND_COLOR.equals(property)) {
if (fViewer != null && fViewer.getTextWidget() != null && fConsole != null) {
fViewer.getTextWidget().setBackground(fConsole.getBackground());
if (fViewer != null && fConsole != null) {
StyledText textWidget = fViewer.getTextWidget();
if (textWidget != null && !textWidget.isDisposed()) {
textWidget.setBackground(fConsole.getBackground());
}
}
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_WRAP_LINES)
|| property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_LINES)
Expand Down Expand Up @@ -471,7 +481,10 @@ public void setFocus() {
* font
*/
protected void setFont(Font font) {
getViewer().getTextWidget().setFont(font);
StyledText textWidget = getViewer().getTextWidget();
if (textWidget != null && !textWidget.isDisposed()) {
textWidget.setFont(font);
}
}

/**
Expand All @@ -482,7 +495,7 @@ protected void setFont(Font font) {
*/
protected void setTabs(int tabs) {
StyledText textWidget = getViewer().getTextWidget();
if (textWidget != null) {
if (textWidget != null && !textWidget.isDisposed()) {
textWidget.setTabs(tabs);
}
}
Expand Down

0 comments on commit 5039ad3

Please sign in to comment.