mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
gg: image: return an optional instead of panic(); darwin: fix nsstring()
This commit is contained in:
parent
0bdb096bfa
commit
9e12095111
9 changed files with 101 additions and 66 deletions
|
@ -26,10 +26,12 @@ pub mut:
|
|||
|
||||
fn C.sg_isvalid() bool
|
||||
|
||||
// TODO return ?Image
|
||||
pub fn (mut ctx Context) create_image(file string) Image {
|
||||
if !C.sg_isvalid() {
|
||||
// Sokol is not initialized yet, add stbi object to a queue/cache
|
||||
//ctx.image_queue << file
|
||||
stb_img := stbi.load(file)
|
||||
stb_img := stbi.load(file) or { return Image{} }
|
||||
img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -55,7 +57,7 @@ fn create_image(file string) Image {
|
|||
println('gg.create_image(): file not found: $file')
|
||||
return Image{} // none
|
||||
}
|
||||
stb_img := stbi.load(file)
|
||||
stb_img := stbi.load(file) or { return Image{} }
|
||||
mut img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -70,7 +72,7 @@ fn create_image(file string) Image {
|
|||
}
|
||||
|
||||
pub fn create_image_from_memory(buf byteptr, bufsize int) Image {
|
||||
stb_img := stbi.load_from_memory(buf, bufsize)
|
||||
stb_img := stbi.load_from_memory(buf, bufsize) or { return Image{} }
|
||||
mut img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue