mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 15:07:26 +01:00
internal/debug: bug fix: panic when Go command is not found with -tags=ebitenginedebug
This commit is contained in:
parent
9de408a25c
commit
74765c995e
@ -15,6 +15,7 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path"
|
||||
@ -34,12 +35,20 @@ func FirstCaller() (file string, line int, ok bool) {
|
||||
ebitengineFileDirOnce.Do(func() {
|
||||
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2")
|
||||
out, err := cmd.Output()
|
||||
if errors.Is(err, exec.ErrNotFound) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("debug: go list -f {{.Dir}} failed: %v", err))
|
||||
}
|
||||
ebitengineFileDir = filepath.ToSlash(strings.TrimSpace(string(out)))
|
||||
})
|
||||
|
||||
// Go command is not found.
|
||||
if ebitengineFileDir == "" {
|
||||
return "", 0, false
|
||||
}
|
||||
|
||||
// Relying on a caller stacktrace is very fragile, but this is fine as this is only for debugging.
|
||||
var ebitenPackageReached bool
|
||||
for i := 0; ; i++ {
|
||||
|
@ -166,8 +166,6 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.Sh
|
||||
if debug.IsDebug {
|
||||
if file, line, ok := debug.FirstCaller(); ok {
|
||||
c.firstCaller = fmt.Sprintf("%s:%d", file, line)
|
||||
} else {
|
||||
c.firstCaller = "(internal)"
|
||||
}
|
||||
}
|
||||
q.commands = append(q.commands, c)
|
||||
|
Loading…
Reference in New Issue
Block a user