|
||||||||||||||||||
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!) |
|
![]() deavik Member since: 6/14/2005 From: Baltimore, MD, United States |
||||
|
|
||||
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] |
||||
|
||||
![]() python_regious Member since: 2/28/2001 From: Bath, United Kingdom |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Xeee Member since: 1/28/2001 From: al Jizah, Egypt |
||||
|
|
||||
| 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. |
||||
|
||||
![]() deavik Member since: 6/14/2005 From: Baltimore, MD, United States |
||||
|
|
||||
Quote: 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: 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. |
||||
|
||||
![]() deavik Member since: 6/14/2005 From: Baltimore, MD, United States |
||||
|
|
||||
Oh, I've finally solved it, whew. I had mistakenly kept the definitions in file1.cpp inside a namespace . Thanks for the help, guys! |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|