Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Context.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@
return nil
}

func (c *GIUContext) WithLock(fn func()) {

Check failure on line 217 in Context.go

View workflow job for this annotation

GitHub Actions / Lint

exported: exported method GIUContext.WithLock should have comment or be unexported (revive)
c.m.Lock()
defer c.m.Unlock()
fn()
}
Comment on lines +217 to +221
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

The WithLock method lacks documentation. Add a comment explaining its purpose for thread-safe execution of functions while holding the context mutex.

Copilot uses AI. Check for mistakes.

func (c *GIUContext) load(id any) (*state, bool) {
if v, ok := c.state.Load(id); ok {
if s, ok := v.(*state); ok {
Expand Down
30 changes: 16 additions & 14 deletions MasterWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,25 @@ func (w *MasterWindow) beforeRender() {

Context.FontAtlas.rebuildFontAtlas()

// process texture load requests
if Context.textureLoadingQueue != nil && Context.textureLoadingQueue.Length() > 0 {
for Context.textureLoadingQueue.Length() > 0 {
request, ok := Context.textureLoadingQueue.Remove().(textureLoadRequest)
Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request")
NewTextureFromRgba(request.img, request.cb)
Context.WithLock(func() {
// process texture load requests
if Context.textureLoadingQueue != nil && Context.textureLoadingQueue.Length() > 0 {
for Context.textureLoadingQueue.Length() > 0 {
request, ok := Context.textureLoadingQueue.Remove().(textureLoadRequest)
Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request")
NewTextureFromRgba(request.img, request.cb)
}
}
}

// process texture free requests
if Context.textureFreeingQueue != nil && Context.textureFreeingQueue.Length() > 0 {
for Context.textureFreeingQueue.Length() > 0 {
request, ok := Context.textureFreeingQueue.Remove().(textureFreeRequest)
Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request")
request.tex.tex.Release()
// process texture free requests
if Context.textureFreeingQueue != nil && Context.textureFreeingQueue.Length() > 0 {
for Context.textureFreeingQueue.Length() > 0 {
request, ok := Context.textureFreeingQueue.Remove().(textureFreeRequest)
Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request")
request.tex.tex.Release()
}
}
}
})
}

func (w *MasterWindow) afterRender() {
Expand Down
8 changes: 6 additions & 2 deletions Texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ type textureFreeRequest struct {
// NOTE: remember to call it after NewMasterWindow!
func EnqueueNewTextureFromRgba(rgba image.Image, loadCb func(t *Texture)) {
Assert((Context.textureLoadingQueue != nil), "", "EnqueueNewTextureFromRgba", "you need to call EnqueueNewTextureFromRgba after giu.NewMasterWindow call!")
Context.textureLoadingQueue.Add(textureLoadRequest{rgba, loadCb})
Context.WithLock(func() {
Context.textureLoadingQueue.Add(textureLoadRequest{rgba, loadCb})
})
}

// NewTextureFromRgba creates a new texture from image.Image and, when it is done, calls loadCallback(loadedTexture).
Expand All @@ -39,7 +41,9 @@ func NewTextureFromRgba(rgba image.Image, loadCallback func(*Texture)) {
}

runtime.SetFinalizer(giuTex, func(tex *Texture) {
Context.textureFreeingQueue.Add(textureFreeRequest{tex})
Context.WithLock(func() {
Context.textureFreeingQueue.Add(textureFreeRequest{tex})
})
})

loadCallback(giuTex)
Expand Down
Loading