From e26daa0d9f7eca3675350caadec8fdf3b25c6430 Mon Sep 17 00:00:00 2001 From: Lukas Malkmus Date: Sun, 10 Sep 2017 00:31:35 +0200 Subject: [PATCH 1/4] Update matrix.go --- matrix.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/matrix.go b/matrix.go index 59f9eb3..426d72f 100644 --- a/matrix.go +++ b/matrix.go @@ -122,13 +122,23 @@ type RGBLedMatrix struct { const MatrixEmulatorENV = "MATRIX_EMULATOR" // NewRGBLedMatrix returns a new matrix using the given size and config -func NewRGBLedMatrix(config *HardwareConfig) (Matrix, error) { +func NewRGBLedMatrix(config *HardwareConfig) (m Matrix, err error) { + defer func() { + if r := recover(); r != nil { + var ok bool + err, ok = r.(error) + if !ok { + err = fmt.Errorf("error creating matrix: %v", r) + } + } + }() + if isMatrixEmulator() { return buildMatrixEmulator(config), nil } w, h := config.geometry() - m := C.led_matrix_create_from_options(config.toC(), nil, nil) + m = C.led_matrix_create_from_options(config.toC(), nil, nil) b := C.led_matrix_create_offscreen_canvas(m) c := &RGBLedMatrix{ Config: config, From 407045aff74d8763894afd3694ad1e9d1b92e72d Mon Sep 17 00:00:00 2001 From: Lukas Malkmus Date: Sun, 10 Sep 2017 00:38:14 +0200 Subject: [PATCH 2/4] Update matrix.go --- matrix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix.go b/matrix.go index 426d72f..65d97b3 100644 --- a/matrix.go +++ b/matrix.go @@ -138,9 +138,9 @@ func NewRGBLedMatrix(config *HardwareConfig) (m Matrix, err error) { } w, h := config.geometry() - m = C.led_matrix_create_from_options(config.toC(), nil, nil) + m := C.led_matrix_create_from_options(config.toC(), nil, nil) b := C.led_matrix_create_offscreen_canvas(m) - c := &RGBLedMatrix{ + c = &RGBLedMatrix{ Config: config, width: w, height: h, matrix: m, From cf3bb1dea8b8a602d94dcf9a673ef6883494e768 Mon Sep 17 00:00:00 2001 From: Lukas Malkmus Date: Sun, 10 Sep 2017 00:39:58 +0200 Subject: [PATCH 3/4] Update matrix.go --- matrix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix.go b/matrix.go index 65d97b3..3125bfd 100644 --- a/matrix.go +++ b/matrix.go @@ -122,7 +122,7 @@ type RGBLedMatrix struct { const MatrixEmulatorENV = "MATRIX_EMULATOR" // NewRGBLedMatrix returns a new matrix using the given size and config -func NewRGBLedMatrix(config *HardwareConfig) (m Matrix, err error) { +func NewRGBLedMatrix(config *HardwareConfig) (c Matrix, err error) { defer func() { if r := recover(); r != nil { var ok bool From 511237f615e66c0bfa839757f89f514059323283 Mon Sep 17 00:00:00 2001 From: Lukas Malkmus Date: Sun, 10 Sep 2017 00:42:36 +0200 Subject: [PATCH 4/4] Update matrix.go --- matrix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix.go b/matrix.go index 3125bfd..8523004 100644 --- a/matrix.go +++ b/matrix.go @@ -147,7 +147,7 @@ func NewRGBLedMatrix(config *HardwareConfig) (c Matrix, err error) { buffer: b, leds: make([]C.uint32_t, w*h), } - if c.matrix == nil { + if m == nil { return nil, fmt.Errorf("unable to allocate memory") }