From e26daa0d9f7eca3675350caadec8fdf3b25c6430 Mon Sep 17 00:00:00 2001 From: Lukas Malkmus Date: Sun, 10 Sep 2017 00:31:35 +0200 Subject: [PATCH] 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,