-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
47 lines (39 loc) · 904 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2022, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This is initially adapted from https://github.com/vulkan-go/asche
// Copyright © 2017 Maxim Kupriianov <[email protected]>, under the MIT License
package vgpu
import (
"fmt"
"log"
"runtime/debug"
vk "github.com/goki/vulkan"
)
func IsError(ret vk.Result) bool {
return ret != vk.Success
}
func NewError(ret vk.Result) error {
if ret != vk.Success {
err := fmt.Errorf("vulkan error: %s (%d)", vk.Error(ret).Error(), ret)
if Debug {
log.Println(err)
debug.PrintStack()
}
return err
}
return nil
}
func IfPanic(err error, finalizers ...func()) {
if err != nil {
for _, fn := range finalizers {
fn()
}
panic(err)
}
}
func CheckErr(err *error) {
if v := recover(); v != nil {
*err = fmt.Errorf("%+v", v)
}
}