UltraStar-Deluxe / USDX

The free and open source karaoke singing game UltraStar Deluxe, inspired by Sony SingStarâ„¢
https://usdx.eu
GNU General Public License v2.0
812 stars 160 forks source link

[OS X] dglOpenGL context initialization crashes on OS X el capitain #84

Closed basisbit closed 8 years ago

basisbit commented 8 years ago

see #29 and https://github.com/SaschaWillems/dglOpenGL/issues/4

After switching to dglOpenGL, executing the game fails on Mac OS X el capitain in dglOpelGL.pas procedure ReadCoreVersion line 19615 AnsiBuffer := glGetString(GL_VERSION);

Compiling works without any problem and dglOpenGL works without any problem on Linux and Windows based systems.

Function is called from https://github.com/UltraStar-Deluxe/USDX/blob/master/src/base/UGraphic.pas#L681

RattleSN4K3 commented 8 years ago

I've read -framework OpenGL is required.

https://wiki.libsdl.org/FAQMacOSX

to the GCC or LD arguments in your Makefile

Without knowing much of the Mac world, I assume it is currently setup using the Carbon framework (in xcode proj). Using configure, the framework is unspecified. Maybe give it a try adding it to the LDFLAGS.

Have you tried debugging? Not sure where it could crash, but something like that as a start:

  glcontext := SDL_GL_CreateContext(Screen);
  if glcontext = nil then
  begin
    // dialog + log entry
    Log.LogCritical(SDL_GetError(), 'UGraphic.InitializeScreen');
    SDL_Quit();
  end;

Or adding this: SDL_GL_MakeCurrent(screen, glcontext);

From what I read, glGetString is returning a null pointer (nil) and thus it crashes.

rhaamo commented 8 years ago

Thanks for hints.

I have tried the -framework thing and nothing better.

otool -L ./UltraStarDeluxe.app/Contents/MacOS/ultrastardx | grep -i opengl
    /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)

The code hint doesn't help too. Added them on L697 in src/base/UGraphic.pas.

Investigation continue.

rhaamo commented 8 years ago

And current stack trace:

Thread 1 received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt full
#0  0x0000000000000000 in ?? ()
No symbol table info available.
#1  0x00000001000406b7 in READCOREVERSION () at lib/dglOpenGL/dglOpenGL.pas:19615
        ANSIBUFFER = 0x0
        BUFFER = 0x0
        MAJORVERSION = 0
        MINORVERSION = 0
#2  0x0000000000000000 in ?? ()
No symbol table info available.

Can't get anything better ATM. configure with: ./configure PFLAGS="-g -Px86_64 -B" and make with make macosx-standalone-app

RattleSN4K3 commented 8 years ago

As I read ReadExtensions and ReadImplementationProperties (even in different order stating from a help message from one of the devs) (or ActivateRenderingContext) are crucial for initializing dglOpenGL, I think InitOpenGL is bugging.

  if not InitOpenGL() then
  begin
    Log.LogCritical('InitOpenGL failed', 'UGraphic.InitializeScreen');
    SDL_Quit; // use SDL quit just for debugging purpose
    Exit;
  end;

Probably the standard libs are the problem and aren't linked (same problem with the SDL2 headers). dglOpenGL.pas

  {$IFDEF darwin}
    OPENGL_LIBNAME = 'libGL.dylib';
    GLU_LIBNAME = 'libGLU.dylib';
  {$ELSE}
    OPENGL_LIBNAME = 'libGL.so.1';
    GLU_LIBNAME = 'libGLU.so.1';
  {$ENDIF} 

function InitOpenGL(LibName: String = OPENGL_LIBNAME; GLULibName: String = GLU_LIBNAME): Boolean;
RattleSN4K3 commented 8 years ago

https://wiki.delphigl.com/index.php/dglOpenGL.pas/en

Along with the removal of .NET support, support for loading methods dynamically has also been removed and is no longer possible with the standard header. So it's crucial to call either AtivateRenderingContext or ReadExtensions alongside with ReadImplementationProperties in your application before accessing any of the OpenGL functions. Otherwise you'll likely be prompted with an access violation at address 0x00000000

So the used libs have to be linked, if i'm correct.

rhaamo commented 8 years ago

So after some other tries and things, I found https://gist.github.com/frostney/1044116 I tested and the fix was to change LIB NAMES to:

    OPENGL_LIBNAME = '/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib';
    GLU_LIBNAME = '/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib';

And it works...

basisbit commented 8 years ago

that's ugly but they should not change anyway

should be fixed using the configure / make script, but this solution is ok for now.