Unable to load image #1808
Answered
by
hajimehoshi
EldersJavas
asked this question in
Q&A
-
My project is unable to load image. Version Acodefile, err := os.Open("D:\\GitHub\\LowGame\\src\\img\\ebiten.png")
tmp, _, _ :=image.Decode(file)
if err != nil {
log.Fatal(err)
}
img = ebiten.NewImageFromImage(tmp) Report Wrong:panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x5a2edb]
goroutine 1 [running, locked to thread]:
github.com/hajimehoshi/ebiten/v2.NewImageFromImage(0x0, 0x0, 0x0)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/image.go:789 +0x3b
main.init.0()
D:/GitHub/LowGame/main.go:25 +0xf3 Version Bcodeimg, _, _ =ebitenutil.NewImageFromFile("D:\\GitHub\\LowGame\\src\\img\\ebiten.png") Report Wrong:panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x5a25b2]
goroutine 6 [running]:
github.com/hajimehoshi/ebiten/v2.(*Image).isDisposed(...)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/image.go:59
github.com/hajimehoshi/ebiten/v2.(*Image).DrawImage(0xc0000f8700, 0x0, 0xc000067d38)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/image.go:181 +0x52
main.(*Game).Draw(0xc00000ad08, 0xc0000f8700)
D:/GitHub/LowGame/main.go:35 +0x208
github.com/hajimehoshi/ebiten/v2.(*imageDumperGame).Draw(0xc0001521e0, 0xc0000f8700)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/run.go:123 +0x4f
github.com/hajimehoshi/ebiten/v2.(*uiContext).update(0xa893a0, 0x1, 0x0, 0x0)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/uicontext.go:209 +0x150
github.com/hajimehoshi/ebiten/v2.(*uiContext).Update(0xa893a0, 0xc00027a4e0, 0x0)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/uicontext.go:153 +0xc3
github.com/hajimehoshi/ebiten/v2/internal/uidriver/glfw.(*UserInterface).loop(0xa84600, 0x0, 0x0)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/internal/uidriver/glfw/ui.go:974 +0x158
github.com/hajimehoshi/ebiten/v2/internal/uidriver/glfw.(*UserInterface).Run.func1(0xa84600, 0xc00003c360)
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/internal/uidriver/glfw/run_notsinglethread.go:52 +0xdb
created by github.com/hajimehoshi/ebiten/v2/internal/uidriver/glfw.(*UserInterface).Run
D:/GOPATH/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.1.6/internal/uidriver/glfw/run_notsinglethread.go:36 +0x182 env
Thanks a lot. |
Beta Was this translation helpful? Give feedback.
Answered by
hajimehoshi
Sep 12, 2021
Replies: 1 comment 2 replies
-
You should get an error from Decode. Then
is the correct code. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
EldersJavas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should get an error from Decode. Then
is the correct code.