Home » Community » Forums » OpenGL » Extension loading trouble using C++ (solved it!)
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Extension loading trouble using C++ (solved it!)
Post New Topic  Post Reply 
Hi, I am trying to load and use extensions in this way:

file1.h: // extension loading header file

extern	PFNGLCREATESHADERPROC				glCreateShader;
...

file1.cpp: // extension loading source file

PFNGLCREATESHADERPROC		glCreateShader		= 0;

glCreateShader = reinterpret_cast<PFNGLCREATESHADERPROC> (glXGetProcAddressARB ("glCreateShader")); // this is not NULL I checked
...

file2.cpp // the file where I want to use the functions

...
glCreateShader (...);
...




The problem is that the program crashes with a seg fault the first time I call glCreateShader in file2.cpp. If I move everything in file1.cpp to file2.cpp and call it before using glCreateShader then it works as expected. I tried moving everything out to make the code neater, and then these problems started happenning.

I'm sorry this seems more of a C++ programming problem of mine, but a lot of those reading this will have done very similar things in their own projects, so maybe you could give me some pointers (pun not intended )

/edit: Even in file2.cpp, glCreateShader is not NULL, just pointing to a wrong memory address maybe?

[Edited by - deavik on February 12, 2006 6:57:26 AM]

 User Rating: 1313   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

You actually including file1.cpp in your build? I had a similar problem (not with OpenGL though) that drove me insane, only to find that I wasn't actually compiling the right files.

Write out the memory address in file1 and file2 and see if they're the same for a start...

If at first you don't succeed, redefine success.

 User Rating: 1552   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

I don't know if this will solve your problem or not.

1. make sure you have only 1 definition for glCreateShader.
i.e. like this: PFNGLCREATESHADERPROC glCreateShader = NULL;
the above statement should exist in one .cpp file only.

2. you can have as much declarations as you want.
i.e. like this: extern PFNGLCREATESHADERPROC glCreateShader;
you can put it every where.
usually it is placed in a .h file and this file is included by many other files.

3. make sure there are no statements like #include <something.cpp>, only #include header files, but not cpp's.

hope this helps.

 User Rating: 1029   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by python_regious
You actually including file1.cpp in your build? I had a similar problem (not with OpenGL though) that drove me insane, only to find that I wasn't actually compiling the right files.

Write out the memory address in file1 and file2 and see if they're the same for a start...

I'm including all the files in the build, that's not a problem. About the memory address matching, I actually did that before even my first post, and they didn't match. But that seemed so unlikely that I dismissed it as a silly error and forgot about it. Now that you mention it, the address after the block of code in file1.cpp is 0x804f6c4, and in file2.cpp it is 0x8049e2c. How do you think this can happen? There is only 1 definition across all my source files.

Quote:
Original post by Xeee
I don't know if this will solve your problem or not.

1. make sure you have only 1 definition for glCreateShader.
i.e. like this: PFNGLCREATESHADERPROC glCreateShader = NULL;
the above statement should exist in one .cpp file only.

That's quite all right for me. I think I would have had a linker error if not, though which would be easier to solve . And also I'm not including source files.


 User Rating: 1313   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Oh, I've finally solved it, whew. I had mistakenly kept the definitions in file1.cpp inside a namespace .

Thanks for the help, guys!

 User Rating: 1313   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: