nimPNG
nimPNG copied to clipboard
nim 1.6.0 savePNG results in too nested template instantiation
Nim Compiler Version 1.6.0 [Windows: amd64]
savePNG(filename, data, LCT_RGBA, 32, swCanvas32.w, swCanvas32.h)
results in:
C:\Users\user\git\nico\nico\backends\sdl2.nim(807, 10) template/generic instantiation of `savePNG` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(3131, 18) template/generic instantiation of `savePNGImpl` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(3002, 26) template/generic instantiation of `encodePNG` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(2967, 21) template/generic instantiation of `encodePNG` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(2954, 17) template/generic instantiation of `encoderCore` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(2873, 18) template/generic instantiation of `frameConvert` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(2833, 24) template/generic instantiation of `preProcessScanLines` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(2642, 13) template/generic instantiation of `filter` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG.nim(2620, 30) template/generic instantiation of `filterMinsum` from here
C:\Users\user\.nimble\pkgs\nimPNG-#head\nimPNG\filters.nim(138, 31) Error: template instantiation too nested
please report this to Nim repo as a regression. it is very hard to fix it from nimPNG.
Hmm, I've just gone and tested this with Nim 1.4 and Nim 1.2 and get the same behaviour, so it seems this is not caused by a recent change in Nim.
Testing using a cutdown example doesn't reproduce the problem.
import nimPNG
import os
import strformat
import strutils
import times
import sdl2_nim/sdl
var swCanvas32: Surface
var writePath = "."
proc saveScreenshot*() =
echo "saveScreenshot"
createDir(writePath & "/screenshots")
let filename = joinPath(writePath, joinPath("screenshots", "screenshot-$1T$2.png".format(getDateStr(), getClockStr())))
var data = newSeq[uint8](swCanvas32.w * swCanvas32.h * 4)
copyMem(data[0].addr, swCanvas32.pixels, swCanvas32.w * swCanvas32.h * 4)
var res = savePNG(filename, data, LCT_RGBA, 32, swCanvas32.w, swCanvas32.h)
echo "saved screenshot to: ", filename
saveScreenshot()
Compiles successfully, but similar code used in nico gives the original error, though I'm unsure why, will investigate further.
looks like a global scope pollution to me. some inner template in filters.nim might collide with other template from somewhere.
a workaround is, you can write a helper module+proc to force instantiate nimPNG generics and then reexport those non-generic proc.