bimg icon indicating copy to clipboard operation
bimg copied to clipboard

Trim fails with SIGSEGV: segmentation when using in multiple goroutines

Open piotrkochan opened this issue 5 years ago • 1 comments

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:

  1. There is no Trim operation
  2. When there is only one running goroutine.

piotrkochan avatar Jun 14 '19 10:06 piotrkochan

Hi @piotrkochan, am facing the same problem, any work around this issue?

oSethoum avatar Aug 22 '23 20:08 oSethoum