feenkcom / gtoolkit

Glamorous Toolkit is the Moldable Development environment. It empowers you to make systems explainable through experiences tailored for each problem.
https://gtoolkit.com
MIT License
1.11k stars 49 forks source link

Error when resizing Glutin Morphic World #590

Closed syrel closed 5 years ago

syrel commented 5 years ago
Error: SubscriptOutOfBounds: 418783
Bitmap(Object)>>error:
[ :err :rcvr | 
"Handle a drawing error"
| errCtx errMorph |
errCtx := thisContext.
[ errCtx := errCtx sender.
"Search the sender chain to find the morph causing the problem"
[ errCtx notNil and: [ errCtx receiver isMorph not ] ]
    whileTrue: [ errCtx := errCtx sender ].
"If we're at the root of the context chain then we have a fatal drawing problem"
errCtx ifNil: [ ^ self handleFatalDrawingError: err ].
errMorph := errCtx receiver.
"If the morph causing the problem has already the #drawError flag set,
            then search for the next morph above in the caller chain."
errMorph hasProperty: #errorOnDraw ] whileTrue.
errMorph setProperty: #errorOnDraw toValue: true.
"Install the old error handler, so we can re-raise the error"
rcvr error: err ] in WorldState>>displayWorldSafely: in Block: [ :err :rcvr | ...
BlockClosure>>cull:cull:
[ :ex | errorHandlerBlock cull: ex description cull: ex receiver ] in BlockClosure>>ifError: in Block: [ :ex | errorHandlerBlock cull: ex description cul...etc...
BlockClosure>>cull:
Context>>evaluateSignal:
Context>>handleSignal:
SubscriptOutOfBounds(Exception)>>signal
SubscriptOutOfBounds class>>signalFor:lowerBound:upperBound:in:
SubscriptOutOfBounds class>>signalFor:lowerBound:upperBound:
SubscriptOutOfBounds class>>signalFor:
Bitmap(Object)>>errorSubscriptBounds:
Bitmap(Object)>>at:
[ :eachRectangle | 
| aDamage h index bits |
bits := display bits.
aDamage := eachRectangle
    intersect: (0 @ 0 extent: buffer extent - (1 @ 1)).
aDamage top floor to: aDamage bottom ceiling do: [ :y | 
    h := display width * y + 1.
    aDamage left floor to: aDamage right ceiling do: [ :x | 
        index := h + x.
        thePixels at: index put: (bits at: index) ] ] ] in [ "force re-layout if needed"
submorphs do: [ :m | m fullBounds ].
aWorldState checkIfUpdateNeeded
    ifFalse: [ ^ self ].
"display is already up-to-date"
glutinWindow ifNil: [ ^ self ].
worldDamageRects := aWorldState
    drawWorld: aWorld
    submorphs: submorphs
    invalidAreasOn: self canvas.
"repair world's damage on canvas"
handsToDraw := aWorldState
    selectHandsToDrawForDamage: worldDamageRects.
handDamageRects := handsToDraw
    collect: [ :h | h savePatchFrom: self canvas ].
allDamage := worldDamageRects , handDamageRects.
handsToDraw reverseDo: [ :h | self canvas fullDrawMorph: h ].   "draw hands onto world canvas"

"*make this true to flash damaged areas for testing*"
WorldState debugShowDamage
    ifTrue: [ aWorld flashRects: allDamage color: Color black ].
self canvas finish.

"quickly copy altered rects of canvas to Display:"
thePixels := FFIExternalArray
    fromHandle: buffer pixels
    type: FFIUInt32
    size: display stride * display height.
allDamage
    do: [ :eachRectangle | 
        | aDamage h index bits |
        bits := display bits.
        aDamage := eachRectangle
            intersect: (0 @ 0 extent: buffer extent - (1 @ 1)).
        aDamage top floor to: aDamage bottom ceiling do: [ :y | 
            h := display width * y + 1.
            aDamage left floor to: aDamage right ceiling do: [ :x | 
                index := h + x.
                thePixels at: index put: (bits at: index) ] ] ].
renderer presentBuffer: buffer areas: allDamage.
handsToDraw do: [ :h | h restoreSavedPatchOn: self canvas ] "restore world canvas under hands" ] in GlutinWorldRenderer>>displayWorldState:ofWorld:submorphs: in Block: [ :eachRectangle | ...
OrderedCollection>>do:
[ "force re-layout if needed"
submorphs do: [ :m | m fullBounds ].
aWorldState checkIfUpdateNeeded
    ifFalse: [ ^ self ].
"display is already up-to-date"
glutinWindow ifNil: [ ^ self ].
worldDamageRects := aWorldState
    drawWorld: aWorld
    submorphs: submorphs
    invalidAreasOn: self canvas.
"repair world's damage on canvas"
handsToDraw := aWorldState
    selectHandsToDrawForDamage: worldDamageRects.
handDamageRects := handsToDraw
    collect: [ :h | h savePatchFrom: self canvas ].
allDamage := worldDamageRects , handDamageRects.
handsToDraw reverseDo: [ :h | self canvas fullDrawMorph: h ].   "draw hands onto world canvas"

"*make this true to flash damaged areas for testing*"
WorldState debugShowDamage
    ifTrue: [ aWorld flashRects: allDamage color: Color black ].
self canvas finish.

"quickly copy altered rects of canvas to Display:"
thePixels := FFIExternalArray
    fromHandle: buffer pixels
    type: FFIUInt32
    size: display stride * display height.
allDamage
    do: [ :eachRectangle | 
        | aDamage h index bits |
        bits := display bits.
        aDamage := eachRectangle
            intersect: (0 @ 0 extent: buffer extent - (1 @ 1)).
        aDamage top floor to: aDamage bottom ceiling do: [ :y | 
            h := display width * y + 1.
            aDamage left floor to: aDamage right ceiling do: [ :x | 
                index := h + x.
                thePixels at: index put: (bits at: index) ] ] ].
renderer presentBuffer: buffer areas: allDamage.
handsToDraw do: [ :h | h restoreSavedPatchOn: self canvas ] "restore world canvas under hands" ] in GlutinWorldRenderer>>displayWorldState:ofWorld:submorphs: in Block: [ "force re-layout if needed"...
BlockClosure>>ensure:
[ owner := activeProcess.
aBlock
    ensure: [ owner := nil ] ] in Mutex>>critical: in Block: [ owner := activeProcess....
[ caught := true.
self wait.
blockValue := mutuallyExcludedBlock value ] in Semaphore>>critical: in Block: [ caught := true....
BlockClosure>>ensure:
Semaphore>>critical:
Mutex>>critical:
Glutin class>>critical:
GlutinWorldRenderer>>displayWorldState:ofWorld:submorphs:
WorldState>>displayWorld:submorphs:
WorldMorph>>displayWorld
[ aWorld displayWorld ] in WorldState>>displayWorldSafely: in Block: [ aWorld displayWorld ]
BlockClosure>>on:do:
BlockClosure>>ifError:
WorldState>>displayWorldSafely:
syrel commented 5 years ago

works now