Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: GLEW Problems (access violation error)  (Read 5244 times)

0 Members and 1 Guest are viewing this topic.

mike38

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Michael's Software Site
GLEW Problems (access violation error)
« on: August 15, 2013, 12:48:32 pm »
Hi all,

I recently ran into some trouble trying to get GLEW working in SFML.
Currently the SFML libraries are static, and the GLEW library is dynamically linked- with a DLL in beside the .exe, is this correct?

The problem is that when I try and use any of the GL extensions I get an access violation error:

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "Test", sf::Style::Default, sf::ContextSettings(32));

        glewExperimental = GL_TRUE;
       
         GLenum glewErr = glewInit();

         if (glewErr != GLEW_OK)
                 std::cout << "GLEW not OK...";
         else
                 std::cout << "GLEW is OK...";

         if (!GLEW_ARB_vertex_buffer_object)
         {
                std::cout << "Not supported...";
         }

         unsigned int temp = 0;
         glGenBuffers(1,&temp); // Access violation reading '0x000...'
 

Visual C++ throws an access violation error at the glGenBuffers line.
Most similar problems I see online are because of omitting 'glewInit()', or 'glewExperimental = GL_TRUE'.

Is it possibly a problem with the way I have set up GLEW?

(glewInit returns GLEW_OK, and by using glGetString(GL_EXTENSIONS) [or something] I am sure that my drivers support VBOs, they are part of the standard anyway aren't they?)

Any help would be much appreciated,
thanks.
« Last Edit: August 15, 2013, 12:50:28 pm by mike38 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: GLEW Problems (access violation error)
« Reply #1 on: August 15, 2013, 01:06:27 pm »
SFML uses GLEW as well, so if you want to use your own GLEW stuff, you'll have to call glewInit() before SFML gets the chance to, at least that's what I've once done.

Not sure if that will work with the linking, because SFML include GLEW in its own libraries and will link it statically, which IIRC will define GLEW_STATIC. Maybe try to switch to linking GLEW static as well?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mike38

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Michael's Software Site
Re: GLEW Problems (access violation error)
« Reply #2 on: August 15, 2013, 01:57:27 pm »
Okay, thanks for the reply  :).

I reverted back to the static glew32s.lib library, and I moved glewInit() to the very top of main().

However, VC++2010 complains that:

1>sfml-graphics-s-d.lib(glew.obj) : error LNK2005: ___glewCopyTexSubImage3D already defined in glew32s.lib(glew.obj)
1>sfml-graphics-s-d.lib(glew.obj) : error LNK2005: ___glewDrawRangeElements already defined in glew32s.lib(glew.obj)
... (about a few hundred similar lines)

This is the problem I had with the static library before: SFML hides GLEW enough that we aren't allowed to use it, but not enough that we can run our own copy as well...?

What do you think?

Edit

I tried *not* linking and including the glew32s.lib library- I thought since SFML has included the GLEW library already it is pointless. This seems to work, and the duplicate object errors are not there- however glGenBuffers is still 0x00...

Also, now glewInit() is an unresolved external symbol. I think that maybe that SFML will do this to stop it being called twice, as it is called as part of the SFML load-up? However as I said glGenBuffers is still null...
« Last Edit: August 15, 2013, 02:56:26 pm by mike38 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: GLEW Problems (access violation error)
« Reply #3 on: August 15, 2013, 02:56:04 pm »
Okay when I once used my own version of GLEW I linked SFML and my GLEW version dynamically, while SFML still linked/included GLEW statically.

But I guess you'll just have to try stuff.
Link GLEW dynamic and SFML static.
Or link GLEW and SFML dynamic.

Laurent should really, really, really change how SFML is built.  :(
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mike38

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Michael's Software Site
Re: GLEW Problems (access violation error)
« Reply #4 on: August 15, 2013, 03:00:00 pm »
Thanks.

Yeah I know, but if you look at my edit above, to be honest I have tried mostly everything...
And I'd prefer to use the static SFML libraries.

I frustratingly see other projects using VBOs successfully with SFML but with little explanation.


I personally, but I think that  the community as a whole would really appreciate it the SFML team could demonstrate the correct method of using GLEW and SFML perhaps in a tutorial, or if the GLEW mess was fixed so the correct way would become self-evident.

Using GLEW seems like a pretty basic part of SFML, especially for 3D applications like mine where using immediate OpenGL commands is useless and also deprecated, and VBOs, VAOs, etc. are becoming the standard.
« Last Edit: August 15, 2013, 03:06:00 pm by mike38 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: GLEW Problems (access violation error)
« Reply #5 on: August 15, 2013, 03:06:21 pm »
I don't really have much experience on that level...
Can you explain again, what you're trying to achieve?

If you just want to use OpenGL functions, you can read this official tutorial.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mike38

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Michael's Software Site
Re: GLEW Problems (access violation error)
« Reply #6 on: August 15, 2013, 03:11:27 pm »
Using Vertex Buffer Objects, i.e. though the glGenBuffers() etc. functions.
These functions are part of (afaik) OpenGL extensions, which require GLEW (or GLEE) to run.
I can't get GLEW to run properly in an SFML based context.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: GLEW Problems (access violation error)
« Reply #7 on: August 15, 2013, 04:27:42 pm »
The safest setup, if you want to link SFML statically, is to link GLEW statically as well, using the headers provided in the SFML sources (in /extlibs). You don't need to explicitly link to GLEW yourself, since it is included in sfml-graphics.
Laurent Gomila - SFML developer

mike38

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Michael's Software Site
Re: GLEW Problems (access violation error)
« Reply #8 on: August 15, 2013, 05:21:34 pm »
Hi Laurent, and thanks very much for the reply :)

I did what you said, and although it didn't work at first I juggled around glewInit() until it did!
It isn't working quite as it's supposed to, but as the compiler seems to be OK I think that the problems are now of OpenGL, so I should be able to hammer them out soon.

So thankyou very much Laurent or eXpl0it3r for your time, knowledge, and patience :)

 

anything