1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-26 03:18:22 +01:00

Fix memory leak bug

This commit is contained in:
DanyLE 2022-03-15 19:11:19 +01:00
parent 172a62192e
commit fcc7b13d28
17 changed files with 38 additions and 32 deletions

View File

@ -87,7 +87,6 @@ DiyaBoot >> exampleNodes [
text extent: 200@320.
text wordWrap: true.
^ root
"text rotation:(Float pi / 4.0); scale: 2.0@2.0."
]
{ #category : #events }
@ -123,6 +122,7 @@ DiyaBoot >> processEvent: event [
mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ].
mappedEvt type = SDL_FINGERMOTION ifTrue:[^self setCursorPosition: mappedEvt ].
mappedEvt type = SDL_MOUSEMOTION ifTrue:[DiyaRendererContext uniqueInstance mouse: (mappedEvt x) @ (mappedEvt y)].
mappedEvt free.
]
{ #category : #events }
@ -144,8 +144,8 @@ DiyaBoot >> render [
text extent: 80@40.
text fontSize: 20.
text color: Color red.
DiyaRendererContext uniqueInstance.
self GLinit.
OpenGL viewportX: 0 Y:0 W: display w H: display h.
[ running ] whileTrue: [
delta := DiyaClock uniqueInstance delta asMilliSeconds.
text data: ('FPS:', (1000/delta) asInteger asString).
@ -154,6 +154,7 @@ DiyaBoot >> render [
self processEvent: event
].
DiyaRenderer uniqueInstance render.
SDL2 glSwapWindow: window.
delta := DiyaClock uniqueInstance delta asMilliSeconds.
SDL2 delay: (0 max: (1000/ self class maxFPS) asInteger - delta). "60 fps"
@ -234,9 +235,11 @@ DiyaBoot >> startx [
display ifNil: [ ^self error: 'Please run #init before this method' ].
self createWindow.
self createGLContext.
SDL2 glMakeCurrent: window context: context.
"SDL2 glMakeCurrent: window context: context."
self showSystemInfo.
DiyaRendererContext uniqueInstance display: display; useProjection: OrthoProjectionMatrix.
DiyaRendererContext
uniqueInstance display: display;
useProjection: OrthoProjectionMatrix.
self render.
context delete.
window destroy.

View File

@ -16,7 +16,7 @@ DiyaFontFamily class >> fromFace: face [
{ #category : #accessing }
DiyaFontFamily >> addFace: face [
name ifNil: [ name := face familyName ].
styles at: face styleName ifAbsentPut: (DiyaFontStyle fromFace: face).
styles at: face styleName ifAbsentPut: [(DiyaFontStyle fromFace: face)].
]
{ #category : #initialization }

View File

@ -149,18 +149,21 @@ DiyaNode >> scale: anObject [
{ #category : #accessing }
DiyaNode >> setUpShader [
|mem|
mem := self tf asGLBuffer.
shader use;
setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat;
setUniform: #u_projection value: {GL_FALSE. context projection buffer};
setUniform: #u_resolution value: { context resolution x. context resolution y };
setUniform: #u_texture value: 0;
setUniform: #u_transform value: {GL_TRUE. self tf asGLBuffer}.
setUniform: #u_transform value: {GL_TRUE. mem}.
context mouse ifNotNil: [
"in shader, window origin is bottom left conor of the window
the mouse position should be transformed to this coodinate"
shader setUniform: #u_mouse value:
{ context mouse x. context resolution y - context mouse y }.
].
mem free.
]
{ #category : #accessing }

View File

@ -18,6 +18,7 @@ Class {
{ #category : #'instance creation' }
DiyaRendererContext class >> cleanUpInstance: singleton [
singleton ifNil:[^self].
singleton destroy
]
@ -52,7 +53,6 @@ DiyaRendererContext >> initialize [
vao bind.
vbo bind: GL_ARRAY_BUFFER.
projection := Array2D identity: 4.
]
{ #category : #accessing }

View File

@ -24,14 +24,20 @@ DiyaSingleton class >> new [
{ #category : #'instance creation' }
DiyaSingleton class >> reset [
|singleton|
singleton := singletons at: self class ifAbsent: [ ^ self ].
|singleton key|
key := self class asString asSymbol.
singleton := singletons at: key ifAbsent: [ ^ self ].
self cleanUpInstance: singleton.
singletons removeKey: self class
singletons removeKey: key
]
{ #category : #'instance creation' }
DiyaSingleton class >> uniqueInstance [
singletons at: self class ifAbsentPut: super new.
^ singletons at: self class
^singletons at: self class asString asSymbol ifAbsentPut: [ super new ].
]
{ #category : #initialization }
DiyaSingleton >> initialize [
super initialize.
Transcript show: 'Initialise unique instance of ', self className; cr.
]

View File

@ -19,6 +19,7 @@ OpenGLSL class >> attachShader: shader to: program [
{ #category : #'instance creation' }
OpenGLSL class >> cleanUpInstance: singleton [
singleton ifNil:[^self].
singleton delete
]

View File

@ -3,8 +3,7 @@ Class {
#superclass : #DiyaBaseObject,
#instVars : [
'uname',
'location',
'value'
'location'
],
#pools : [
'OpenGLConstants',
@ -89,7 +88,7 @@ OpenGLSLUniform >> location: anObject [
]
{ #category : #accessing }
OpenGLSLUniform >> setUniformValue [
OpenGLSLUniform >> setUniformValue: value [
^ self subclassResponsibility
]
@ -104,15 +103,9 @@ OpenGLSLUniform >> uname: anObject [
uname := anObject
]
{ #category : #accessing }
OpenGLSLUniform >> value [
^ value
]
{ #category : #accessing }
OpenGLSLUniform >> value: values [
location = -1 ifTrue: [ ^self ].
value := values.
self setUniformValue.
self setUniformValue: values.
]

View File

@ -9,6 +9,6 @@ Class {
}
{ #category : #accessing }
Uniform1F >> setUniformValue [
Uniform1F >> setUniformValue: value [
OpenGLSLUniform uniform1f: location value: value
]

View File

@ -9,6 +9,6 @@ Class {
}
{ #category : #accessing }
Uniform1i >> setUniformValue [
Uniform1i >> setUniformValue: value [
OpenGLSLUniform uniform1i: location value: value
]

View File

@ -9,6 +9,6 @@ Class {
}
{ #category : #accessing }
Uniform2F >> setUniformValue [
Uniform2F >> setUniformValue: value [
OpenGLSLUniform uniform2f: location value: value first value: value last
]

View File

@ -9,6 +9,6 @@ Class {
}
{ #category : #accessing }
Uniform2i >> setUniformValue [
Uniform2i >> setUniformValue: value [
OpenGLSLUniform uniform2i: location value: value first value: value last
]

View File

@ -9,6 +9,6 @@ Class {
}
{ #category : #accessing }
Uniform3F >> setUniformValue [
Uniform3F >> setUniformValue: value [
OpenGLSLUniform uniform3f: location value: value first value: (value at:2) value: value last
]

View File

@ -9,6 +9,6 @@ Class {
}
{ #category : #accessing }
Uniform3i >> setUniformValue [
Uniform3i >> setUniformValue: value [
OpenGLSLUniform uniform3i: location value: value first value: (value at:2) value: value last
]

View File

@ -9,7 +9,7 @@ Class {
}
{ #category : #accessing }
Uniform4F >> setUniformValue [
Uniform4F >> setUniformValue: value [
OpenGLSLUniform uniform4f: location
value: value first
value: (value at:2)

View File

@ -9,7 +9,7 @@ Class {
}
{ #category : #accessing }
Uniform4i >> setUniformValue [
Uniform4i >> setUniformValue: value [
OpenGLSLUniform uniform4i: location
value: value first
value: (value at:2)

View File

@ -9,7 +9,7 @@ Class {
}
{ #category : #accessing }
UniformMatrix3fv >> setUniformValue [
UniformMatrix3fv >> setUniformValue: value [
OpenGLSLUniform
uniformMatrix3fv: location
count: 1

View File

@ -9,7 +9,7 @@ Class {
}
{ #category : #accessing }
UniformMatrix4fv >> setUniformValue [
UniformMatrix4fv >> setUniformValue: value [
OpenGLSLUniform
uniformMatrix4fv: location
count: 1