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

Author Topic: Upgrading from 2.3.2 to 2.4.2, crashes on glewInit  (Read 2405 times)

0 Members and 1 Guest are viewing this topic.

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Upgrading from 2.3.2 to 2.4.2, crashes on glewInit
« on: March 08, 2018, 02:12:29 pm »
Hey all,

I'm currently trying to upgrade from 2.3.2 to 2.4.2, but when I change the static libs of 2.3.2 to the static libs of 2.4.2 and run the application, my code crashes on glewInit returning GLEW_ERROR_NO_GL_VERSION.
I haven't changed any code from the working 2.3 version to the crashing 2.4 version, so I'm assuming it's because of something internally being different.

The code for my init function is below, any help would be greatly appreciated!~
Anasky

Code: [Select]
void clsOpenGLDataHelper::Init( )
{
// Initialize window, ~OpenGL deletes it
m_WindowMode = sf::VideoMode( m_ScreenWidth, m_ScreenHeight );
m_ContextSettings = sf::ContextSettings( 24U, 8U, 4U, 4U, 6U, sf::ContextSettings::Attribute::Default );
m_Style = sf::Style::None;
m_Window = new sf::Window( );
m_Window->setVerticalSyncEnabled( true );
m_Window->create( m_WindowMode, "Client", m_Style, m_ContextSettings );
m_Window->setPosition( sf::Vector2i( ( m_ScreenWidth - m_WindowMode.width ) / 2, ( m_ScreenHeight - m_WindowMode.height ) / 2 ) );
m_Window->setActive( true );
OpenGL.Resize( );
clsOpenGL::CheckOGLerror( );
m_WindowHandle = m_Window->getSystemHandle( );

glewExperimental = GL_TRUE;
GLenum init = glewInit( );
if (init != GLEW_OK)
{
throw std::runtime_error( std::string( "glewInit failed" ) + (const char*) glewGetErrorString( init ) );
}
if (!glewIsSupported( "GL_VERSION_1_5" ) && !glewIsSupported( "GL_ARB_vertex_buffer_object" ))
{
throw std::runtime_error( "ARB_vertex_buffer_object not supported!" );
}
clsOpenGL::CheckOGLerror( );
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Upgrading from 2.3.2 to 2.4.2, crashes on glewInit
« Reply #1 on: March 08, 2018, 02:21:55 pm »
glewInit has to be called before any SFML window/graphics resources (e.g. RenderWindow) is created. You're just lucky that it worked before somehow.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Upgrading from 2.3.2 to 2.4.2, crashes on glewInit
« Reply #2 on: March 08, 2018, 02:37:30 pm »
Moving this part of the code to the top of the function still gives the same error though..
Code: [Select]
glewExperimental = GL_TRUE;
GLenum init = glewInit( );
if (init != GLEW_OK)
{
throw std::runtime_error( std::string( "glewInit failed" ) + (const char*) glewGetErrorString( init ) );
}
if (!glewIsSupported( "GL_VERSION_1_5" ) && !glewIsSupported( "GL_ARB_vertex_buffer_object" ))
{
throw std::runtime_error( "ARB_vertex_buffer_object not supported!" );
}
clsOpenGL::CheckOGLerror( );

Correction: Moving it to the top of the main function doesn't work either. If I do that with 2.3.2, it also doesn't work.
« Last Edit: March 08, 2018, 04:03:20 pm by Anasky »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Upgrading from 2.3.2 to 2.4.2, crashes on glewInit
« Reply #3 on: March 08, 2018, 06:31:22 pm »
Since I assume m_Window is a member variable, once the constructor is called m_Window will be default initialized, which then would still be before your glewInit call.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Upgrading from 2.3.2 to 2.4.2, crashes on glewInit
« Reply #4 on: March 08, 2018, 06:36:18 pm »
m_Window is a pointer member variable ;) I made it a pointer to prevent that from happening. Meaning it won't be done beforehand.

Some googling revealed that glew requires OpenGL to be initialised beforehand. As far as I'm aware, SFML does this already meaning I shouldn't be doing it manually? However, if I'd do this before the new sf::Window(); call, it would be before the OpenGL init right?
« Last Edit: March 08, 2018, 07:09:40 pm by Anasky »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Upgrading from 2.3.2 to 2.4.2, crashes on glewInit
« Reply #5 on: March 08, 2018, 08:35:29 pm »
What does "initialize OpenGL" mean?

Maybe get your GLEW setup to work and then add SFML.

Also try calling glGetString(GL_VERSION) yourself to see what GLEW might have issues with.

Alternatively you could use glLoadGen like SFML switched to from GLEW. ;)
« Last Edit: March 09, 2018, 12:47:28 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/