bimg
bimg copied to clipboard
Trim fails with SIGSEGV: segmentation when using in multiple goroutines
Example code:
package main
import (
"fmt"
"github.com/h2non/bimg"
"sync"
)
func process (img string, wg *sync.WaitGroup) {
buffer, err := bimg.Read(img)
if err != nil {
panic(err)
}
source := bimg.NewImage(buffer)
options := bimg.Options{
Height: 500,
Width: 300,
Type: bimg.JPEG,
Trim: true,
//Gravity: bimg.GravitySmart,
//Background: bimg.Color{B: 255, G: 255, R: 255},
}
newImage, err := source.Process(options)
if err != nil {
panic(err)
}
fmt.Print(newImage)
}
func main() {
wg := &sync.WaitGroup{}
wg.Add(2)
go process("/home/user/photo/2B/39/90/00/0/@T1210160125-000_0001.png", wg)
go process("/home/user/photo/2B/39/90/00/0/@T1210160125-000_0002.png", wg)
wg.Wait()
}
Code fails with error:
(bimg:24025): GLib-GObject-CRITICAL **: 12:30:25.872: g_value_type_compatible: assertion 'G_TYPE_IS_VALUE (src_type)' failed
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x7f34d473f3af]
runtime stack:
runtime.throw(0x50de46, 0x2a)
/usr/local/go/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:374 +0x4a9
.......
But it works when:
- There is no Trim operation
- When there is only one running goroutine.
Hi @piotrkochan, am facing the same problem, any work around this issue?