Skip to content

Exception thrown from stbi_load_from_file

In trying to use Flippy, I uncovered a bug in your library https://forum.nim-lang.org/t/5426

import os
import stb_image/read as stbi

var
  width, height, channels: int
  data: seq[uint8]

for file in walkFiles "*.png":
  echo file
  
try:
  data = stbi.load("bluestar.png", width, height, channels, stbi.Default)
  #echo fopen("bluestar.png", "rb")
  echo "yum"
except: 
  let e = getCurrentException()
  let msg = getCurrentExceptionMsg()
  echo "Got exception ", repr(e), " with message ", msg

outputs

a.png
bluestar.png
Got exception ref 006DE028 --> [parent = nil,
name = 0042F1B6"STBIException",
msg = 006DD0D0"can't fopen",
trace = 006DE050@[[procname = 0042F351"tmp3",
line = 12,
filename = 0042F358"C:\\Nim\\NimExamples\\MyRecipes\\tmp3.nim"], [procname = 0042F170"load",
line = 91,
filename = 0042F0C8"C:\\Users\\sivad\\.nimble\\pkgs\\stb_image-2.3\\stb_image\\read.nim"]],
raiseId = 0,
up = nil]
 with message can't fopen