diff --git a/internal/debug/caller.go b/internal/debug/caller.go index 690cad15f..3fd059235 100644 --- a/internal/debug/caller.go +++ b/internal/debug/caller.go @@ -30,8 +30,16 @@ var ( ebitengineFileDirOnce sync.Once ) +type CallerType int + +const ( + CallerTypeNone CallerType = iota + CallerTypeRegular + CallerTypeInternal +) + // FirstCaller returns the file and line number of the first caller outside of Ebitengine. -func FirstCaller() (file string, line int, ok bool) { +func FirstCaller() (file string, line int, callerType CallerType) { ebitengineFileDirOnce.Do(func() { cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2") out, err := cmd.Output() @@ -46,7 +54,7 @@ func FirstCaller() (file string, line int, ok bool) { // Go command is not found. if ebitengineFileDir == "" { - return "", 0, false + return "", 0, CallerTypeNone } // Relying on a caller stacktrace is very fragile, but this is fine as this is only for debugging. @@ -66,11 +74,17 @@ func FirstCaller() (file string, line int, ok bool) { continue } - if path.Dir(file) == ebitengineFileDir || path.Dir(file) == ebitengineFileDir+"/colorm" || path.Dir(file) == ebitengineFileDir+"/text" || path.Dir(file) == ebitengineFileDir+"/text/v2" { + if path.Dir(file) == ebitengineFileDir { continue } - return file, line, true + if strings.HasPrefix(path.Dir(file), ebitengineFileDir+"/") && !strings.HasPrefix(path.Dir(file), ebitengineFileDir+"/examples/") { + if strings.HasPrefix(path.Dir(file), ebitengineFileDir+"/internal/") { + return file, line, CallerTypeInternal + } + continue + } + return file, line, CallerTypeRegular } - return "", 0, false + return "", 0, CallerTypeNone } diff --git a/internal/graphicscommand/commandqueue.go b/internal/graphicscommand/commandqueue.go index 72e3940e6..a7714fb0d 100644 --- a/internal/graphicscommand/commandqueue.go +++ b/internal/graphicscommand/commandqueue.go @@ -163,9 +163,14 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.Sh c.shader = shader c.uniforms = uniforms c.fillRule = fillRule + c.firstCaller = "" if debug.IsDebug { - if file, line, ok := debug.FirstCaller(); ok { + file, line, typ := debug.FirstCaller() + switch typ { + case debug.CallerTypeRegular: c.firstCaller = fmt.Sprintf("%s:%d", file, line) + case debug.CallerTypeInternal: + c.firstCaller = fmt.Sprintf("%s:%d (internal)", file, line) } } q.commands = append(q.commands, c)