IPicture Problems

Started by
2 comments, last by leehairy 19 years, 10 months ago
When I run my program I get a fatal error (and naturally, it crashes). It compiles just fine. When I debug I find that the program has its problem at the glBindTexture(GL_TEXTURE_2D, texid); segment at the end. The error I get is "First-chance exception in Nexus.exe: 0xC0000005: Access Violation." I don''t know why this isn''t working; I have an image in the images folder of my program called test.bmp. This is the code I use to call the Ipicture functions: GLuint *test; BuildTexture("Images/test.bmp", *test); As mentioned before, it compiles with no errors but crashes in the BuildTexture(); function. Any help?
"Honesty, hard work, and determination are the keys to success in life...if you can fake that, you''ve got it made. " -- Groucho Marx
Advertisement
GLuint *test;
BuildTexture("Images/test.bmp", *test);

You are deferencing an unitialised pointer.

I presume the fn() definition is

void BuildTexture(char *image, int *id);

If this is the case, you need to pass in the address of the integer like so

int IdThatWillBeSetByFunction;
BuildTexture("Images/test.bmp", &IdThatWillBeSetByFunction);

------------ Your example says --------
Create a pointer called "test" which "points to" a value of "unkown". And give that to the function

Hope this helps a little.. for a better understanding see the CFaq by Steve Summit.. Its explained very well in there.






Oh...lol.

That helps, thanks, but the function is

int BuildTexture(char *szPathName, GLuint &texid).

I fixed it...I just declare GLuint test;, then I simply pass it off as test. No & or * operators . *hits self on head*

Thanks again.

"Honesty, hard work, and determination are the keys to success in life...if you can fake that, you''ve got it made. " -- Groucho Marx
int BuildTexture(char *szPathName, GLuint &texid)

If that is the definition it must be C++, C doesnt support the reference declaration.

Note that,

int BuildTexture(char *szPathName, GLuint &texid) -- reference

and

int BuildTexture(char *szPathName, GLuint *texid) -- pointer

are *very* similar.

Both internally pass a pointer to the variable texid, but the reference declaration - automatically dereferences the variable in the funtion body thus eliminating the need for dereferences in the code.

eg
int x(int &y)                  int x(int &*y){                              { y = 10;                         *y = 10;}                              }int x(int *y)                  int x(int **y){                              {  *y = 10;                       **y = 10;}                              }

Both work the same - albeit some subtle semantics. I suggest you read up on references and pointers and make sure you thoroughly understand them.


This topic is closed to new replies.

Advertisement