getting a strange error when i try to read a text file on my windows 8.1 machine.
basically i tried only opening the file and read it with the readAll proc but both it and readFile proc do not read the file.
i'm using gcc 5.3 mingw64 but i'm stumped on this one maybe file encoding issue i don't know.
anybody run into this?
edit: forgot to mention getting segmentation fault on when it tries to read this file.
here is the code i'm having trouble with
import "opengl-1.0/opengl"
var
vert_atr*: GLuint
mvp_id*: GLuint
prog_id*:GLint
p_id*:GLuint
proc create_frag(shader:string): GLuint
proc create_vert(shader:string): GLuint
proc readUserFile(name:string): array[1,string] =
var file: FILE
if open(file,name) == true:
result = [readAll(file).string]
close(file)
else:
echo("error on file: ", name)
close(file)
proc create_program*(f,v: string) =
prog_id = glCreateProgram()
glAttachShader(prog_id.GLuint,create_frag(f))
glAttachShader(prog_id.GLuint,create_vert(v))
#glBindAttribLocation(cast[GLuint](prog_id),1,"vertexs")
#glBindAttribLocation(prog_id,2,"MVP")
glLinkProgram(prog_id.GLuint)
glValidateProgram(prog_id.GLuint)
vert_atr = glGetAttribLocation(prog_id.GLuint,"vertexs")
mvp_id = glGetUniformLocation(prog_id.GLuint,"MVP")
p_id = glGetUniformLocation(prog_id.GLuint,"P")
#echo ("mvp id: ", mvp_id, "prog_id: " , prog_id)
var status: GLint
glGetProgramiv(prog_id.GLuint,GL_LINK_STATUS.GLenum,addr status)
if status == GLint(0):
echo "program did not link"
quit()
proc create_frag(shader:string): GLuint =
var format : array[1,string] = readUserFile(shader)
var shader_id = glCreateShader(GL_FRAGMENT_SHADER.GLenum)
var source = allocCstringArray(format)
glShaderSource(shader_id,GLsizei(1),source,nil)
glCompileShader(shader_id)
deallocCstringArray(source)
var status : GLint = 0;
glGetShaderiv(shader_id,GL_COMPILE_STATUS.GLenum,addr status)
if status == GLint(0):
var msgsize : GLsizei
glGetShaderiv(shader_id,GL_INFO_LOG_LENGTH,msgsize.addr);
var message : cstring
glGetShaderInfoLog(shader_id,GLsizei(1000),msgsize.addr,message)
echo message
quit()
return shader_id
proc create_vert(shader:string): GLuint =
var format : array[1,string] = readUserFile(shader)
var shader_id = glCreateShader(GL_VERTEX_SHADER.GLenum)
var source = allocCstringArray(format)
glShaderSource(shader_id,GLsizei(1),source,nil)
glCompileShader(shader_id)
deallocCstringArray(source)
var status : GLint = 0;
glGetShaderiv(shader_id,GL_COMPILE_STATUS.GLenum,addr status)
if status == GLint(0):
var msgsize : GLsizei
glGetShaderiv(shader_id,GL_INFO_LOG_LENGTH,msgsize.addr);
var message : cstring
glGetShaderInfoLog(shader_id,GLsizei(1000),msgsize.addr,message)
echo message
quit()
return shader_id
and here is the traceback
Traceback (most recent call last)
main.nim(68) main
main.nim(50) main
model_handler.nim(12) init
model.nim(26) create
program.nim(24) create_program
program.nim(44) create_frag
program.nim(14) readUserFile
sysio.nim(267) open
sysio.nim(243) fopen
widestrs.nim(111) newWideCString
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
> Process terminated with exit code 1
as we can see widestr.nim is for some reason being calledMy guess is, that newWideCString() is called to create the filename for the windows system open function. I would debug that name first.
EDIT: I looked up what sysio.nim in line 243 does (see your stacktrace)
when defined(cpp):
proc wfopen(filename, mode: WideCString): pointer {.
importcpp: "_wfopen((const wchar_t*)#, (const wchar_t*)#)", nodecl.}
So there is a problem with the "filename" or "mode". Hope that helps you to find the problem!