Skip to main content
gamedev.net
🔒 Locked

Access violation while initializing

Started by Phynix 3 replies 1.5k views
Original Post
Phynix
Phynix
I decided to create a shader in my program, but now the future's looking a bit shady.

Bad pun aside, I just ran code from http://nehe.gamedev.net/data/articles/article.asp?article=21 (the full linking code is near the bottom of that page); However, when I do, it throws an access violation in memory location 0x00000 or something like that. The full linking code I'm using is below:

void mlInitShaders(){	char * my_fragment_shader_source="void main()\n{\ngl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n}";	// Get Vertex And Fragment Shader Sources	GLenum my_program;	GLenum my_vertex_shader;	GLenum my_fragment_shader;	// Create Shader And Program Objects	my_program = glCreateProgramObjectARB();	my_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	// Load Shader Sources	glShaderSourceARB(my_fragment_shader, 1, (const GLcharARB**)&my_fragment_shader_source, NULL);	// Compile The Shaders	glCompileShaderARB(my_fragment_shader);	// Attach The Shader Objects To The Program Object	glAttachObjectARB(my_program, my_fragment_shader);	// Link The Program Object	glLinkProgramARB(my_program);	// Use The Program Object Instead Of Fixed Function OpenGL	glUseProgramObjectARB(my_program);} 


(Oh, and how do you get those scrolling boxes you can put code in without taking as much space?) Thanks!
Sik_the_hedgehog
Sik_the_hedgehog
Quote:
Original post by Phynix
(Oh, and how do you get those scrolling boxes you can put code in without taking as much space?)
Use the source tag.

Oh, by the way, an address of 0 is basically NULL. What version of OpenGL are you using? Also, what are the addresses of those functions? (assuming you know how to deal with function pointers) Maybe those functions aren't available in your system and thereby they aren't being loaded.

Even better, use the debugger to run the program and tell us where does it crash.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Phynix
Phynix
All right, thanks Sik_the_hedgehog.
The souce is below (Again), and the program crashes when I try to create the shader and program objects.
void mlInitShaders(){	char * my_fragment_shader_source="void main()\n{\ngl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n}";	// Get Vertex And Fragment Shader Sources	GLenum my_program;	GLenum my_vertex_shader;	GLenum my_fragment_shader;	// Create Shader And Program Objects	my_program = glCreateProgramObjectARB();	// <- crashes here	//unhandled exception at 0x00000...	my_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	// Load Shader Sources	glShaderSourceARB(my_fragment_shader, 1, (const GLcharARB**)&my_fragment_shader_source, NULL);	// Compile The Shaders	glCompileShaderARB(my_fragment_shader);	// Attach The Shader Objects To The Program Object	glAttachObjectARB(my_program, my_fragment_shader);	// Link The Program Object	glLinkProgramARB(my_program);	// Use The Program Object Instead Of Fixed Function OpenGL	glUseProgramObjectARB(my_program);}

Though you just asked for my OpenGL version, I decided it wouldn't hurt to give you a bit more information.
Provider ATI Technologies Inc.
Direct3D Version 8.14.10.0700
OpenGL Version 6.14.10.9017

Also, this is a fairly new computer (about 2 or 3 weeks old).
21st Century Moose
21st Century Moose
You need to do a wglGetProcAddress on glCreateProgramObjectARB, or else use something like GLEW or GLee to initialize your entry points for anything above baseline OpenGL 1.1
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Sik_the_hedgehog
Sik_the_hedgehog
Isn't that code part of the NeHe tutorial? Actually, Phynix, did you put the code that uses GLEW/GLee/whatever is using NeHe? (actually, I think that GLee doesn't even have code besides the header, but you need to link against it)

Quote:
Original post by Phynix
OpenGL Version 6.14.10.9017

That looks like the driver version, not the OpenGL version... unless you're from the future o_o

Quote:
Also, this is a fairly new computer (about 2 or 3 weeks old).

OK, I guess that shaders should work, but no idea if the newest drivers include the ARB functions. Make sure that extensions are effectively being loaded, and if you still get null pointers, you may need to go with the non-ARB equivalents of the functions (which have a somewhat different syntax).
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.