Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash-when-original-fill-used-fresh #2285

Open
FredSoftwares opened this issue Jun 15, 2021 · 1 comment · Fixed by #3673
Open

crash-when-original-fill-used-fresh #2285

FredSoftwares opened this issue Jun 15, 2021 · 1 comment · Fixed by #3673
Labels
bug Something isn't working

Comments

@FredSoftwares
Copy link

FredSoftwares commented Jun 15, 2021

Hi !
This code creates a "saveImage" function to save a very large multilayer image to a file. In my code I pass the content of the saveimage() function which produces the multilayer fyne.CanvasObject to the software.Render() function which is triggered by a save button . This code produces a panic because, according to Andrew "it is necessary to remove ImageFillOriginal beacuse to do an original image fill it needs a 2 pass process which it seems does not work for the 1-pass draw of a software renderer"

Example code:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/driver/software"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
	"image"
	"image/color"
	"image/png"
	"log"
	"os"
)

func main() {
	a := app.New()
	w := a.NewWindow("Sign")
	w.SetContent(container.NewScroll(makePicture()))
	w.Resize(fyne.NewSize(120, 120))
	w.Show()

	// save image button
	w2 := a.NewWindow("Tool Box")
	but := widget.NewButton("screenshot", func() {
		// save the scroll containt to file
		pic := makePicture()
		pic.Resize(fyne.NewSize(200, 200))
		img := software.Render(pic, theme.DarkTheme())
		saveimage(img)
	})
	w2.SetContent(but)
	w2.ShowAndRun()
	w.ShowAndRun()
}

func makePicture() fyne.CanvasObject {
	image := canvas.NewImageFromFile("image.png")
	image.FillMode = canvas.ImageFillOriginal // this line is responsible for the bug
	bg := canvas.NewCircle(color.NRGBA{255, 0, 0, 255})
	bg.StrokeColor = color.White
	bg.StrokeWidth = 5

	bg.Resize(fyne.NewSize(100, 100))
	bg.Move(fyne.NewPos(10, 10))
	c := container.NewMax(image, bg)

	return c
}

func saveimage(out image.Image) {
	path := "test.png"
	outputFile, err := os.Create(path)
	if err != nil {

		log.Println("The image cannot be saved to the file")
	}

	png.Encode(outputFile, out)
	log.Println("Saving image to ", path)

	outputFile.Close()
}

Device :

Linux Manjaro
Go version: 1.6.3
Fyne version: 2.0.3

The error :

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x722b37]

goroutine 18 [running]:
fyne.io/fyne/v2/internal/painter/software.drawPixels(0x0, 0x0, 0x1, 0x1, 0x0, 0xc00039e540, 0x0, 0x0, 0x0, 0x0, ...)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/painter/software/draw.go:84 +0x37
fyne.io/fyne/v2/internal/painter/software.drawImage(0x869630, 0xc000402280, 0xc0001d4000, 0x0, 0xc00039e540, 0x0, 0x0, 0x1, 0x1)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/painter/software/draw.go:80 +0x227
fyne.io/fyne/v2/internal/painter/software.(*Painter).Paint.func1(0x867718, 0xc0001d4000, 0x0, 0x0, 0x4f0000004f000000, 0xc4a7f6621eb7df00)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/painter/software/painter.go:39 +0x29e
fyne.io/fyne/v2/internal/driver.walkObjectTree(0x867718, 0xc0001d4000, 0x0, 0x867658, 0xc00039e440, 0x0, 0x0, 0x4f0000004f000000, 0xc00010fdc8, 0x0, ...)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/util.go:169 +0x482
fyne.io/fyne/v2/internal/driver.walkObjectTree.func1(...)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/util.go:176
fyne.io/fyne/v2/internal/driver.walkObjectTree(0x867658, 0xc00039e440, 0x7b4800, 0x0, 0x0, 0x0, 0x0, 0x4f0000004f000000, 0xc00010fdc8, 0x0, ...)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/util.go:190 +0x3ff
fyne.io/fyne/v2/internal/driver.WalkVisibleObjectTree(0x867658, 0xc00039e440, 0xc000059dc8, 0x0, 0xc00039e540)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/util.go:134 +0x94
fyne.io/fyne/v2/internal/painter/software.(*Painter).Paint(0xd94748, 0x869630, 0xc000402280, 0x0, 0x1)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/painter/software/painter.go:57 +0x17d
fyne.io/fyne/v2/test.(*testCanvas).Capture(0xc000402280, 0xc00039e440, 0x869630)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/test/testcanvas.go:83 +0x26f
fyne.io/fyne/v2/driver/software.Render(0x867658, 0xc00039e440, 0x8653d8, 0xc00030c1e0, 0x6bccff, 0xc000070940)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/driver/software/render.go:29 +0x1ca
main.main.func1()
        /home/fred/Documents/MesDocuments/programmes_fred/go/fyne/image/image.go:31 +0xac
fyne.io/fyne/v2/widget.(*Button).Tapped(0xc000402140, 0xc009e3fd70)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/widget/button.go:177 +0x74
fyne.io/fyne/v2/internal/driver/glfw.(*window).mouseClicked.func7()
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/glfw/window.go:799 +0x38
fyne.io/fyne/v2/internal/driver/glfw.(*window).runEventQueue(0xc00015e700)
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/glfw/window.go:1265 +0x7a
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1
        /home/fred/GO/pkg/mod/fyne.io/fyne/v2@v2.0.3/internal/driver/glfw/window.go:1289 +0x113
exit status 2
@FredSoftwares FredSoftwares added the unverified A bug that has been reported but not verified label Jun 15, 2021
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Jul 5, 2021
@andydotxyz
Copy link
Member

The fix for this sadly is more than a little bug fix can include, moving to Aberlour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants