Skip to content

Commit

Permalink
Merge pull request #298 from hfoxy/main
Browse files Browse the repository at this point in the history
add errors when PixImage is nil
  • Loading branch information
otiai10 authored Jan 19, 2024
2 parents 33edae1 + 604253c commit f395c8b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (client *Client) SetImage(imagepath string) error {
defer C.free(unsafe.Pointer(p))

img := C.CreatePixImageByFilePath(p)
if img == nil {
return fmt.Errorf("failed to create PixImage from file path: %s", imagepath)
}

client.pixImage = img

return nil
Expand All @@ -140,6 +144,10 @@ func (client *Client) SetImageFromBytes(data []byte) error {
}

img := C.CreatePixImageFromBytes((*C.uchar)(unsafe.Pointer(&data[0])), C.int(len(data)))
if img == nil {
return fmt.Errorf("failed to create PixImage from bytes: %d", len(data))
}

client.pixImage = img

return nil
Expand Down

0 comments on commit f395c8b

Please sign in to comment.