Conversation
The example uses 'DrawPreview' which has the path to a image
hard coded, if your installation of the package is different,
it will panic.
Changed to use OS agnostic path building.
It still panic if you run the example from outside the
containing directory.
```
~/study/goLang/canvas/examples/
$ go run text-document/main.go
panic: open ../../resources/lenna.png: no such file or directory
goroutine 1 [running]:
main.drawDocument(0x26da9ad07dc8)
/home/malklera/study/goLang/canvas/examples/text-document/main.go:86 +0x671
main.main()
/home/malklera/study/goLang/canvas/examples/text-document/main.go:34 +0x3bd
exit status 2
```
I think somewhere it has to be indicated that the example has to be
run from its containing directory, but i am not sure where because other
examples use the function too e.g. opengl, tex, gio, fyne
A recommendation, add
// Deprecated: Only for use in examples.
To indicate that the function is not made to be part of the
normal API of the package.
From what i noticed 'DrawPreviewWithAssets' should be marked the same,
mostly because of the function signature, instead of accepting
something like (assets ...any) to make it more generic/flexible.
|
The path building is OS agnostic (it uses filepath) but maybe the environment variables are not the same across OS'? The solution is not better, as you said it limits to executing it from a particular directory. The whole point was not to. The DrawPreviewWithAssets shouldn't be more generic not flexible, it needs those exact byte streams...thanks for looking into this though! How can we fix the root direction for each OS and make this work? |
Put the path building as it was. Now the example can be run from anywhere in the repository.
|
The more you know, just learned that this The reason it panic when i try to run it is because the example seems to have been written before modules was introduced. In my case i have this situation. go env
...
GOPATH='/home/malklera/go'
...
ls /home/malklera/go
bin pkgSo when it tries to build the path, it fails to find Made a new commit with a different take to fix |
The example uses 'DrawPreview' which has the path to a image hard coded, if your installation of the package is different, it will panic.
Changed to use OS agnostic path building.
It still panic if you run the example from outside the containing directory.
I think somewhere it has to be indicated that the example has to be run from its containing directory, but i am not sure where because other examples use the function too e.g. opengl, tex, gio, fyne
A recommendation, add
To indicate that the function is not made to be part of the normal API of the package.
From what i noticed 'DrawPreviewWithAssets' should be marked the same, mostly because of the function signature, instead of accepting something like (assets ...any) to make it more generic/flexible.