Fix no-start issue

This commit is contained in:
NeilClack
2026-03-25 15:13:35 -05:00
parent 57691e6b68
commit 8763f70452
2 changed files with 45 additions and 24 deletions
+42 -21
View File
@@ -67,6 +67,7 @@ import (
"rhemawavetech.com/rhemawave/internal/colors"
"rhemawavetech.com/rhemawave/internal/db"
"rhemawavetech.com/rhemawave/internal/fontManager"
"rhemawavetech.com/rhemawave/internal/logger"
"rhemawavetech.com/rhemawave/internal/mixer"
colorPattern "rhemawavetech.com/rhemawave/internal/pattern/color"
linePattern "rhemawavetech.com/rhemawave/internal/pattern/line"
@@ -207,6 +208,7 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
return fmt.Errorf("unable to fetch font 'Scrambled'")
}
p.font = font
logger.Info("Font name: %s", font.Name)
p.Base.Init(ctx)
@@ -216,11 +218,14 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
return fmt.Errorf("text shader not found")
}
p.shader = textShader
logger.Info("Shader Program ID: %d", textShader.ProgramID)
logger.Info("p.shader Program ID: %d", p.shader.ProgramID)
// Load proclamation words from database
if err := p.loadProclamations(); err != nil {
// Don't stop execution, just show fallback words
p.words = strings.Fields("No Proclamations Selected!")
logger.Error("Error loading proclamations: %v", err)
p.Context.NavigateTo(PROCLAMATIONS)
return nil
}
p.wordIndex = 0
@@ -254,14 +259,17 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
p.lines = NewLineDeque(nLines * 2)
// Calculate space width using the SCALE ratio, not the font size int
spaceGlyph, ok := fm.GetGlyph(p.font.Name, ' ')
spaceGlyph, ok := fm.GetGlyph(font.Name, ' ')
if !ok {
return fmt.Errorf("failed to get space glyph")
}
p.spaceWidth = int32(float32(spaceGlyph.Advance) * p.fontScale)
// Get line height using the SCALE ratio
tmpStrID, _, H, err := fm.NewCreateStringTexture(p.font.Name, "Mg", p.shader)
if fm == nil {
logger.Error("FontManager somehow ended up nil...")
}
tmpStrID, _, H, err := fm.NewCreateStringTexture(font.Name, "Mg", p.shader)
if err != nil {
return fmt.Errorf("failed to create sample texture: %w", err)
}
@@ -270,7 +278,7 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
p.lineCtx = &linePattern.LineRenderContext{
ScreenWidth: p.ScreenWidth,
Font: p.font,
Font: font,
FontScale: p.fontScale,
SpaceWidth: p.spaceWidth,
}
@@ -324,7 +332,7 @@ func (p *ScrollerPage) loadProclamations() error {
// Build word list from selected, available proclamations
for _, proclamation := range proclamations {
if proclamation.Selected && proclamation.Available {
if proclamation.Selected {
// Split content into words and add to list
words := strings.Fields(proclamation.Content)
p.words = append(p.words, words...)
@@ -332,8 +340,7 @@ func (p *ScrollerPage) loadProclamations() error {
}
if len(p.words) == 0 {
p.words = strings.Fields("No Proclamations Selected!")
return fmt.Errorf("no proclamations selected or available")
return fmt.Errorf("Failed to load proclamations, no proclamations selected!")
}
return nil
@@ -590,25 +597,39 @@ func (p *ScrollerPage) Destroy() error {
mixer.Stop(1000, p.Base.Context.CfgPtr)
// GL cleanup — delete all text textures
for i := 0; i < p.lines.Len(); i++ {
line := p.lines.Get(i)
for j := range line.words {
if id := line.words[j].ID; id != 0 {
gl.DeleteTextures(1, &line.words[j].ID)
line.words[j].ID = 0
if p.lines != nil {
for i := 0; i < p.lines.Len(); i++ {
line := p.lines.Get(i)
for j := range line.words {
if id := line.words[j].ID; id != 0 {
gl.DeleteTextures(1, &line.words[j].ID)
line.words[j].ID = 0
}
}
}
}
gl.Flush()
// Drop references for GC
p.lines = nil
p.words = nil
p.lineCtx = nil
p.font = nil
p.shader = nil
p.colorPattern = nil
// Drop references for GC safely
if p.lines != nil {
p.lines = nil
}
if p.words != nil {
p.words = nil
}
if p.lineCtx != nil {
p.lineCtx = nil
}
if p.font != nil {
p.font = nil
}
if p.shader != nil {
p.shader = nil
}
if p.colorPattern != nil {
p.colorPattern = nil
}
return nil
}