Discussion:
glActiveTexture crashes program
(too old to reply)
l***@gmail.com
2007-05-22 17:04:00 UTC
Permalink
i try binding three textures for a shader, code compiles now without
errors (some warnings due scanf, but thats ignoreable)

when i run the program i get the following output, then the
application simply closes...

E:\Coding\current\oglLoader\Release>oglLoader.exe bradley.model
SUCCESS found model file [bradley.cmsh] not found
SUCCESS found texture file [bradley.png] found
ERROR 404 - normalmap file [none] not found
ERROR 404 - heightmap file [none] not found
ERROR 404 - vertex shader file [none] not found
ERROR 404 - fragment shader file [none] not found
version: 5
sucessfully loaded texture map [bradley.png]!

E:\Coding\current\oglLoader\Release>

any ideas whats going on there???

thanks in advance

[...]
#include <GL/glew.h>
#include <GL/glut.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

#include "myClasses.h" // my private helper classes
#include "Mesh.h" // one mesh class
#include <GL/glext.h>
[...]
fprintf (stderr, "sucessfully loaded texture map [%s]!\n",
texturemapfile);
glActiveTexture(GL_TEXTURE0);
cout << "crash in the line above but why?\n";
glBindTexture(GL_TEXTURE_2D, textureMap);
glEnable(GL_TEXTURE_2D);
glUniform1i(textureMap, 1);
[...]
Wolfgang Draxinger
2007-05-22 17:48:06 UTC
Permalink
Post by l***@gmail.com
any ideas whats going on there???
Did you check, if glActiveTexture is a valid pointer after
calling glewInit()? If the extension is not avaliable you'll get
a null pointer, this crashing the program.

Wolfgang Draxinger
--
E-Mail address works, Jabber: ***@jabber.org, ICQ: 134682867
l***@gmail.com
2007-05-23 12:54:54 UTC
Permalink
Post by Wolfgang Draxinger
Did you check, if glActiveTexture is a valid pointer after
calling glewInit()? If the extension is not avaliable you'll get
a null pointer, this crashing the program.
i am not sure if i understood what you mean
but if you mean this:

[code]
glewInit();
if (glewIsSupported("GL_VERSION_2_0"))
printf("Ready for OpenGL 2.0\n");
else {
printf("OpenGL 2.0 not supported\n");
exit(1);
}
[/code]

then yes, i checked it
l***@gmail.com
2007-05-23 13:03:25 UTC
Permalink
Post by Wolfgang Draxinger
Did you check, if glActiveTexture is a valid pointer after
calling glewInit()? If the extension is not avaliable you'll get
a null pointer, this crashing the program.
i think now i understood...
you meant this?

if(glActiveTexture==NULL)
{
printf("glActiveTexture not supported\n");
exit(1);
}

well if i check that in my main.cpp right below glewInit();
its NOT NULL
when i check it where i need it (in mesh.cpp) i get NULL returned...
so ??? why? and what can i do against that problem?

thanks in advance
ShOtGaN
2007-05-24 07:33:14 UTC
Permalink
Post by l***@gmail.com
Post by Wolfgang Draxinger
Did you check, if glActiveTexture is a valid pointer after
calling glewInit()? If the extension is not avaliable you'll get
a null pointer, this crashing the program.
i think now i understood...
you meant this?
if(glActiveTexture==NULL)
{
printf("glActiveTexture not supported\n");
exit(1);
}
well if i check that in my main.cpp right below glewInit();
its NOT NULL
when i check it where i need it (in mesh.cpp) i get NULL returned...
so ??? why? and what can i do against that problem?
thanks in advance
I had the same problem i think.
When i did a call to glActiveTexture my program produced a Invalid
Operation and crashes (under windows).
But i think that my solution was call first glBindTexture and then
glActiveTexture.
I hope that this fix your problem. (and sorry if have some mistakes
writing english) :$
Wolfgang Draxinger
2007-05-24 11:40:07 UTC
Permalink
Post by l***@gmail.com
well if i check that in my main.cpp right below glewInit();
its NOT NULL when i check it where i need it (in mesh.cpp) i
get NULL returned... so ??? why? and what can i do against that
problem?
The pointers to extension functions are only valid within the
context you initialized them. After changing the context the
function pointers are undefined (which means that they may still
be valid, but you don't know for sure). Simple solution: Just
call glewInit() again.

In a real world applications it's always a good idea to keep the
OpenGL context switches to a minimum.

Wolfgang Draxinger
--
E-Mail address works, Jabber: ***@jabber.org, ICQ: 134682867
l***@gmail.com
2007-05-24 17:23:08 UTC
Permalink
wolfgang, you are right, now it compiles and even runs, but the
texture wont show up.

without glUniform1i and glActiveTexture the program runs fine with
textures... so whats wrong??
(note: i do not sue any shaders yet)
l***@gmail.com
2007-05-24 17:25:03 UTC
Permalink
without glUniform1i and glActiveTexture the program runs fine with textures... so whats wrong??
err need to correct myself - does not show up textures
l***@gmail.com
2007-05-24 18:19:08 UTC
Permalink
SORRY - SOLVED!!!
i had GL_TEXTURE1 where GL_TEXTURE0 should be.. dumb mistake - works
now, although tested only with one texture and no shaders :D

thanks a lot guys especially wolfgang for the correct solution!

Loading...