From bd8bf6d97cf8b42e6f85a1cbd5b0ee56b2cf27a6 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Sat, 28 Oct 2023 18:16:02 +0200 Subject: [PATCH] Guard removals of morphs in layouts We have a lot of crashes in the Pharo CI because a test end up trying to remove a presenter from a layout but the presenter has no adapter. Guille told us that it was probably because in non interactive things might happens in different order because of the different threads. Here I'm adding nil guards to prevent those crashes (around 1/3 of each Pharo build end up crashing because of this) I don't know if this is a good solution to fix the root of the problem, but I have no idea how to fix better. I also removed some methods that just called super methods --- .../SpMorphicBoxAdapter.class.st | 18 ++++++------------ .../SpMorphicFrameLayoutAdapter.class.st | 14 +++----------- .../SpMorphicGridAdapter.class.st | 4 +--- .../SpMorphicMillerAdapter.class.st | 7 +++---- .../SpMorphicTabAdapter.class.st | 6 ++++-- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st index 8c5a212b..7858ebba 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st @@ -30,12 +30,6 @@ SpMorphicBoxAdapter >> add: aPresenter [ self add: aPresenter constraints: SpBoxConstraints new ] -{ #category : 'adding' } -SpMorphicBoxAdapter >> add: aPresenter constraints: constraints [ - - super add: aPresenter constraints: constraints -] - { #category : 'private' } SpMorphicBoxAdapter >> addConstraints: constraints toChild: childMorph [ "Adds constraits by child" @@ -254,12 +248,12 @@ SpMorphicBoxAdapter >> newWrapMorph [ { #category : 'accessing' } SpMorphicBoxAdapter >> remove: aPresenter [ - | morph | - morph := aPresenter adapter widget. - startPanel removeMorph: morph. - endPanel removeMorph: morph. - self verifyBoxExtent - + aPresenter adapter ifNotNil: [ :adapter | + | morph | + morph := adapter widget. + startPanel removeMorph: morph. + endPanel removeMorph: morph. + self verifyBoxExtent ] ] { #category : 'accessing' } diff --git a/src/Spec2-Adapters-Morphic/SpMorphicFrameLayoutAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicFrameLayoutAdapter.class.st index c246f8bf..8ad84dfa 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicFrameLayoutAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicFrameLayoutAdapter.class.st @@ -24,12 +24,6 @@ SpMorphicFrameLayoutAdapter >> add: aPresenter [ self add: aPresenter constraints: SpBoxConstraints new ] -{ #category : 'adding' } -SpMorphicFrameLayoutAdapter >> add: aPresenter constraints: constraints [ - - super add: aPresenter constraints: constraints -] - { #category : 'factory' } SpMorphicFrameLayoutAdapter >> addConstraints: constraints toChild: childMorph [ @@ -161,11 +155,9 @@ SpMorphicFrameLayoutAdapter >> newPanelWith: aLayout label: aLabel [ { #category : 'accessing' } SpMorphicFrameLayoutAdapter >> remove: aPresenter [ - | morph | - morph := aPresenter adapter widget. - framePanel removeMorph: morph. - self verifyBoxExtent - + aPresenter adapter ifNotNil: [ :adapter | + framePanel removeMorph: adapter widget. + self verifyBoxExtent ] ] { #category : 'accessing' } diff --git a/src/Spec2-Adapters-Morphic/SpMorphicGridAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicGridAdapter.class.st index 0ef812e9..9ba78d3d 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicGridAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicGridAdapter.class.st @@ -113,7 +113,5 @@ SpMorphicGridAdapter >> newPanel [ { #category : 'removing' } SpMorphicGridAdapter >> remove: aPresenter [ - | morph | - morph := aPresenter adapter widget. - widget removeMorph: morph + aPresenter adapter ifNotNil: [ :adapter | widget removeMorph: adapter widget ] ] diff --git a/src/Spec2-Adapters-Morphic/SpMorphicMillerAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicMillerAdapter.class.st index e241020e..9f67bd86 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicMillerAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicMillerAdapter.class.st @@ -203,10 +203,9 @@ SpMorphicMillerAdapter >> recalculatePages [ { #category : 'accessing' } SpMorphicMillerAdapter >> remove: aPresenter [ - | morph | - needRecalculatePages := true. - morph := aPresenter adapter widget. - innerWidget removeMorph: morph + aPresenter adapter ifNotNil: [ :adapter | + needRecalculatePages := true. + innerWidget removeMorph: adapter widget ] ] { #category : 'accessing' } diff --git a/src/Spec2-Adapters-Morphic/SpMorphicTabAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicTabAdapter.class.st index bae58151..ca30abb3 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicTabAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicTabAdapter.class.st @@ -63,6 +63,8 @@ SpMorphicTabAdapter >> layout: aLayout [ { #category : 'removing' } SpMorphicTabAdapter >> remove: aPresenter [ - widget removePage: (widget pages - detect: [ :each | each actualPageMorph = aPresenter adapter widget ]) + aPresenter adapter ifNotNil: [ :adapter | + | morph | + morph := adapter widget. + widget removePage: (widget pages detect: [ :each | each actualPageMorph = morph ]) ] ]