Closed DubDub2011 closed 8 months ago
Just to add, I assume I've broken something somewhere, but I don't know the internals on where the list of formats is pulled from, so sorry I don't have more helpful reproduction steps, think this one needs to be reverse engineered.
I think this is more an issue with your debugger rather than go?
I don't think so, I've tried running go run main.go
and I'm getting the same error.
panic: failed to decode image assets/blank.png with error image: unknown format
goroutine 1 [running, locked to thread]:
wavefunctioncollapse/gui.NewSimulation({0x528b01, 0x6}, 0x10, 0x9)
C:/Users/{user}/source/repos/Go/Wave-Function-Collapse/gui/gui.go:56 +0x6e7
wavefunctioncollapse/gui.RunSimulation()
C:/Users/{user}/source/repos/Go/Wave-Function-Collapse/gui/gui.go:118 +0x55
main.main()
C:/Users/{user}/source/repos/Go/Wave-Function-Collapse/main.go:6 +0xf
exit status 2
The panic I'm just throwing if I get an error, but that's intentional.
do you have a minimal reproducer?
No sorry, I don't know how I produced the error. The code I've given and asset used is all I have, but as I say pretty sure the code is correct.
Right figured it out from reading the docs, RTFM!
Straight at the top of https://pkg.go.dev/image
Values of the Image interface are created either by calling functions such as NewRGBA and NewPaletted, or by calling Decode on an io.Reader containing image data in a format such as GIF, JPEG or PNG. Decoding any particular image format requires the prior registration of a decoder function. Registration is typically automatic as a side effect of initializing that format's package so that, to decode a PNG image, it suffices to have
import _ "image/png"
in a program's main package. The _ means to import a package purely for its initialization side effects.
Apologies, should have checked there first.
Go version
go1.22.0 windows/amd64
Output of
go env
in your module/workspace:What did you do?
Was trying to decode a .png using
image.Decode
, which should be no harm.Got the "image: unknown format" error out of the Decode func, but I checked and everything I was doing looked correct.
Here is my code:
Attached here is the image:
What did you see happen?
I got to debugging in the source code and found that within the
sniff
function withimage
, the line to load the supported formats,formats, _ := atomicFormats.Load().([]format)
is returning an empty slice.Because there are no formats to compare to, this gives the error. There should always be formats, which is the problem.
This issue started appearing out of nowhere, and I could load the image fine before, and I don't think I did anything in particular differently.
Below demonstrates the line above returning an empty set of formats.
What did you expect to see?
I expect a list of formats to be returned, and png included inside of them, so that my image is successfully decoded.
To fix it, I've tried: