ToDo: investigate - memory leak - occasional freezes, crashes, low (2-3) fps
(box *gtk.Image)
| 14 | // - memory leak |
| 15 | // - occasional freezes, crashes, low (2-3) fps |
| 16 | func renderPreview(box *gtk.Image) { |
| 17 | tickFor := time.Second * 5 // 5 seconds timer |
| 18 | ticker := time.NewTicker(time.Second / 30) // 30 base fps |
| 19 | defer ticker.Stop() |
| 20 | |
| 21 | go func() { |
| 22 | if prefsWin == nil { |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | prefsWin.ConnectCloseRequest(func() bool { |
| 27 | ticker.Stop() |
| 28 | return false |
| 29 | }) |
| 30 | }() |
| 31 | |
| 32 | // memory leak is terrible w/o this |
| 33 | imgCache := make(map[string]*gdk.Paintable) |
| 34 | timeStart := time.Now() |
| 35 | for range ticker.C { |
| 36 | if prefsWin == nil || box == nil || !prefsWin.IsVisible() { |
| 37 | continue |
| 38 | } |
| 39 | |
| 40 | timePassed := time.Since(timeStart).Microseconds() |
| 41 | percent := float64(timePassed) / float64(tickFor.Microseconds()) * 100 |
| 42 | if percent >= 100 { |
| 43 | timeStart = time.Now() |
| 44 | continue |
| 45 | } |
| 46 | |
| 47 | imgFilename, err := core.MakeProgressCircle(percent) |
| 48 | if err != nil { |
| 49 | log.Printf("render preview: %v", err) |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | cached := imgCache[imgFilename] |
| 54 | if cached != nil { |
| 55 | box.SetFromPaintable(cached) |
| 56 | continue |
| 57 | } |
| 58 | |
| 59 | img := gtk.NewImageFromFile(imgFilename) |
| 60 | if img == nil { |
| 61 | continue |
| 62 | } |
| 63 | |
| 64 | paintable := img.Paintable() |
| 65 | if paintable == nil { |
| 66 | continue |
| 67 | } |
| 68 | |
| 69 | curImg := paintable.CurrentImage() |
| 70 | if curImg == nil { |
| 71 | continue |
| 72 | } |
| 73 |
no test coverage detected