glGetString crash

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

glGetString crash

Ryan Joseph
I tried using a core OpenGL context on my old MacBook (2010) and got a crash from glGetString from the Pascal bindings (a legacy 2.x context doesn’t crash).

I pulled out the related functions from glext.pp where it crashes in Load_GL_ARB_blend_func_extended from Load_GL_VERSION_3_3. It looks like the function pointer for glGetString wasn’t loaded but how could that be? I’m using SDL to load the context and I need to use glGetString in order to even return what the highest OpenGL version is on the system.

* thread #1: tid = 0x750fc, 0x00007fff9362ffc8 libGL.dylib`glGetString + 15, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00007fff9362ffc8 libGL.dylib`glGetString + 15
libGL.dylib`glGetString + 15:
-> 0x7fff9362ffc8:  movq   (%rcx), %rdi
   0x7fff9362ffcb:  movq   0x3b0(%rcx), %rcx
   0x7fff9362ffd2:  movl   %eax, %esi
   0x7fff9362ffd4:  popq   %rbp
(lldb) bt
* thread #1: tid = 0x750fc, 0x00007fff9362ffc8 libGL.dylib`glGetString + 15, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00007fff9362ffc8 libGL.dylib`glGetString + 15
    frame #1: 0x00000001000a78fc OpenGL-Tests`GLEXT_$$_LOAD_GL_ARB_BLEND_FUNC_EXTENDED$BOOLEAN$$BOOLEAN + 76
    frame #2: 0x000000010004b6b1 OpenGL-Tests`TEST_1_VERTATTRIBS_$$_TESTVERTATTRIBS + 201
    frame #3: 0x0000000100000ae5 OpenGL-Tests`PASCALMAIN + 69
    frame #4: 0x00000001000205d4 OpenGL-Tests`FPC_SysEntry + 12
    frame #5: 0x0000000100000a4e OpenGL-Tests`FPC_SYSTEMMAIN + 54
    frame #6: 0x00000001000009f4 OpenGL-Tests`start + 52
(lldb)

procedure Load_GL_VERSION_3_3x(var allOK: boolean; out isVersion: Boolean);
var
   dummy: boolean;
begin
  isVersion := Load_GL_ARB_blend_func_extended(true);
  if not isVersion then allOK := false;
  if not Load_GL_ARB_sampler_objects(true) then allOK := false;
  if not Load_GL_ARB_timer_query(true) then allOK := false;
  if not Load_GL_ARB_vertex_type_2_10_10_10_rev(true) then allOK := false;
  Load_GL_VERSION_3_2x(allOK, dummy);
end;


function Load_GL_ARB_blend_func_extended(LoadAsCore: boolean): Boolean;
var
  extstring: String;
begin
  Result := False;
  extstring := String(PChar(glGetString(GL_EXTENSIONS)));

  if LoadAsCore or glext_ExtensionSupported('GL_ARB_blend_func_extended', extstring) then
  begin
    glBindFragDataLocationIndexed := wglGetProcAddress('glBindFragDataLocationIndexed');
    if not Assigned(glBindFragDataLocationIndexed) then Exit;
    glGetFragDataIndex := wglGetProcAddress('glGetFragDataIndex');
    if not Assigned(glGetFragDataIndex) then Exit;
    Result := True;
  end;
end;


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: glGetString crash

Jonas Maebe-3
On 18/02/18 02:59, Ryan Joseph wrote:
> I tried using a core OpenGL context on my old MacBook (2010) and got a crash from glGetString from the Pascal bindings (a legacy 2.x context doesn’t crash).
>
> I pulled out the related functions from glext.pp where it crashes in Load_GL_ARB_blend_func_extended from Load_GL_VERSION_3_3. It looks like the function pointer for glGetString wasn’t loaded but how could that be? I’m using SDL to load the context and I need to use glGetString in order to even return what the highest OpenGL version is on the system.

The crash is inside the glGetString function itself, so its pointer was
loaded properly. That function is trying to load data from a
null-pointer though, so maybe the OpenGL context was not initialised
properly yet.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: glGetString crash

Ryan Joseph-2
Maybe SDL has a bug then because glGetString should never crash.

When are the land Load_GL_VERSION_XXX functions meant to be called in the pipeline? I was calling them before the openGL context is created (which works except for 3.x on the old MacBook) but I just tried calling Load_GL_VERSION_3_0 after the context was created and I got some random errors from OpenGL functions (Load_GL_VERSION_2_1 in a legacy context did work however).

Either way calling Load_GL_VERSION_3_0 before the context is created works on my 2015 Mac but crashes in glGetString on the 2010. Not sure what to make of that.

> On Feb 19, 2018, at 12:41 AM, Jonas Maebe <[hidden email]> wrote:
>
> The crash is inside the glGetString function itself, so its pointer was loaded properly. That function is trying to load data from a null-pointer though, so maybe the OpenGL context was not initialised properly yet.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: glGetString crash

Jonas Maebe-3
On 19/02/18 03:21, Ryan Joseph wrote:
> Maybe SDL has a bug then because glGetString should never crash.

glGetString is not an SDL function, but an OpenGL framework version.

> When are the land Load_GL_VERSION_XXX functions meant to be called in the pipeline? I was calling them before the openGL context is created (which works except for 3.x on the old MacBook) but I just tried calling Load_GL_VERSION_3_0 after the context was created and I got some random errors from OpenGL functions (Load_GL_VERSION_2_1 in a legacy context did work however).

It's invalid to call glGetString before a context has been created,
since it returns information about the context:
https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries 
(or
https://stackoverflow.com/questions/6288759/why-could-glgetstringgl-version-be-causing-a-seg-fault 
)

My guess is that the Load_GL_VERSION_3_3x() function is broken since it
appears to call glGetString before a context has been created, and that
it just happens to work on some (most?) implementations by pure chance.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: glGetString crash

Ryan Joseph


> On Feb 20, 2018, at 4:24 AM, Jonas Maebe <[hidden email]> wrote:
>
> My guess is that the Load_GL_VERSION_3_3x() function is broken since it appears to call glGetString before a context has been created, and that it just happens to work on some (most?) implementations by pure chance.

After a context is created Load_GL_VERSION_3_3 returns false on my 2015 MacBook Pro. Load_GL_VERSION_3_2 returns true but glGetError returns GL_INVALID_ENUM directly after calling it. My system has all extensions for 3.3 so that function is indeed broken.

I guess the fix for now is to use Load_GL_VERSION_3_2 and call glGetError to clear the error which is erroneous it appears.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: glGetString crash

Jonas Maebe-3

Ryan Joseph wrote:
>> On Feb 20, 2018, at 4:24 AM, Jonas Maebe  wrote:
>>
>> My guess is that the Load_GL_VERSION_3_3x() function is broken since it appears to call glGetString before a context has been created, and that it just happens to work on some (most?) implementations by pure chance.
> After a context is created Load_GL_VERSION_3_3 returns false on my 2015 MacBook Pro. Load_GL_VERSION_3_2 returns true but glGetError returns GL_INVALID_ENUM directly after calling it. My system has all extensions for 3.3 so that function is indeed broken.

The brokenness I referred to stemmed from the fact that it calls
glGetString before a context has been created (unless you are only
supposed to call it after creating a context, but that seems rather
weird since afaik you create a context for a particular OpenGL version).

If you first create a context and it then still returns false, it may
also mean that you did not create the context properly.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: glGetString crash

Ryan Joseph


> On Feb 20, 2018, at 2:07 PM, Jonas Maebe <[hidden email]> wrote:
>
> If you first create a context and it then still returns false, it may
> also mean that you did not create the context properly.

It’s up to SDL then I guess but it says I’m getting a 4.1 context (GL_VERSION), which is the highest fully implemented version of OpenGL on this Mac according to “OpenGL Extension Viewer” also. I don’t need any 3.3+ extensions so I’ll just ignore it for now but I think something is wrong.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal