mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 23:17:27 +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
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@ -34,12 +35,20 @@ func FirstCaller() (file string, line int, ok bool) {
|
|||||||
ebitengineFileDirOnce.Do(func() {
|
ebitengineFileDirOnce.Do(func() {
|
||||||
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2")
|
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2")
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
|
if errors.Is(err, exec.ErrNotFound) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("debug: go list -f {{.Dir}} failed: %v", err))
|
panic(fmt.Sprintf("debug: go list -f {{.Dir}} failed: %v", err))
|
||||||
}
|
}
|
||||||
ebitengineFileDir = filepath.ToSlash(strings.TrimSpace(string(out)))
|
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.
|
// Relying on a caller stacktrace is very fragile, but this is fine as this is only for debugging.
|
||||||
var ebitenPackageReached bool
|
var ebitenPackageReached bool
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
|
@ -166,8 +166,6 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.Sh
|
|||||||
if debug.IsDebug {
|
if debug.IsDebug {
|
||||||
if file, line, ok := debug.FirstCaller(); ok {
|
if file, line, ok := debug.FirstCaller(); ok {
|
||||||
c.firstCaller = fmt.Sprintf("%s:%d", file, line)
|
c.firstCaller = fmt.Sprintf("%s:%d", file, line)
|
||||||
} else {
|
|
||||||
c.firstCaller = "(internal)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q.commands = append(q.commands, c)
|
q.commands = append(q.commands, c)
|
||||||
|
Loading…
Reference in New Issue
Block a user