www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Strange segfault (Derelict/OpenGL)

reply "Robin Schroer" <sulamiification gmail.com> writes:
I'm not entirely sure where to post, so I will put it here.

I'm playing around with D and Derelict 3 to make something with 
OpenGL (don't really know what yet). I managed to open a window, 
add an OpenGL context, clear the screen and flip buffers. But as 
soon as I try to render a triangle, my program crashes. I already 
tried hardcoding values in the shaders to rule them out. I end up 
with:

Error executing command run: Program exited with code -11

Upon running with gdb, I get:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()

which is not really helpful to me.

dub -v's output:

[...]

Full exception: 
object.Exception source/dub/generators/build.d(405): Program 
exited with code -11
----------------
dub(pure  safe bool std.exception.enforce!(bool).enforce(bool, 
lazy const(char)[], immutable(char)[], ulong)+0x6b) [0x67346f]
dub(void 
dub.generators.build.BuildGenerator.runTarget(dub.internal.vibeco
pat.inet.path.Path, 
const(dub.compilers.compiler.BuildSettings), 
immutable(char)[][])+0x4dc) [0x62db70]
dub(void 
dub.generators.build.BuildGenerator.generateTargets(dub.generators.generato
.GeneratorSettings, 
const(dub.generators.generator.ProjectGenerator.TargetInfo[immutab
e(char)[]]))+0x231) 
[0x62a75d]
dub(void 
dub.generators.generator.ProjectGenerator.generate(dub.generators.generator.Gener
torSettings)+0x2de) 
[0x62f9a2]
dub(void dub.dub.Dub.generateProject(immutable(char)[], 
dub.generators.generator.GeneratorSettings)+0xaa) [0x5f1f46]
dub(int dub.commandline.GenerateCommand.execute(dub.dub.Dub, 
immutable(char)[][], immutable(char)[][])+0x677) [0x5e5b6b]
dub(int dub.commandline.BuildCommand.execute(dub.dub.Dub, 
immutable(char)[][], immutable(char)[][])+0x8d) [0x5e5e81]
dub(int dub.commandline.RunCommand.execute(dub.dub.Dub, 
immutable(char)[][], immutable(char)[][])+0x8d) [0x5e6041]
dub(int 
dub.commandline.runDubCommandLine(immutable(char)[][])+0x1211) 
[0x5e3b8d]
dub(_Dmain+0x20) [0x5e2334]
dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll().void __lambda1()+0x18) [0x6ce504]
dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate())+0x2a) 
[0x6ce45e]
dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll()+0x30) [0x6ce4c4]
dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate())+0x2a) 
[0x6ce45e]
dub(_d_run_main+0x1a3) [0x6ce3df]
dub(main+0x25) [0x5e2979]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x3dcae21d65]

I am using the current master versions of Derelict, dub 0.9.21, 
dmd v2.066.0, on Linux 3.15.7 x86_64

I can post my source if needed, but it is quite a lot already. 
I'm not really sure if it is my fault or a bug in Derelict or 
dmd, hopefully someone is able to track this down.

--

Robin Schroer
Aug 29 2014
next sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Friday, 29 August 2014 at 11:23:34 UTC, Robin Schroer wrote:
 I'm not entirely sure where to post, so I will put it here.
This is the right place.
 I'm playing around with D and Derelict 3 to make something with 
 OpenGL (don't really know what yet). I managed to open a 
 window, add an OpenGL context, clear the screen and flip 
 buffers. But as soon as I try to render a triangle, my program 
 crashes. I already tried hardcoding values in the shaders to 
 rule them out. I end up with:

 Error executing command run: Program exited with code -11

 Upon running with gdb, I get:

 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()

 which is not really helpful to me.
Can you still try to get a backtrace with `bt`? This looks like it's calling a null function pointer. I'm not familiar with Derelict, but I remember that some initialization needs to be done which involves setting up function pointers; your problem is probably related to that.
Aug 29 2014
parent reply "Robin Schroer" <sulamiification gmail.com> writes:
On Friday, 29 August 2014 at 11:51:47 UTC, Marc Schütz wrote:
 On Friday, 29 August 2014 at 11:23:34 UTC, Robin Schroer wrote:
 Upon running with gdb, I get:

 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()

 which is not really helpful to me.
Can you still try to get a backtrace with `bt`? This looks like it's calling a null function pointer. I'm not familiar with Derelict, but I remember that some initialization needs to be done which involves setting up function pointers; your problem is probably related to that.
Yes, I can: Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? () (gdb) bt #0 0x0000000000000000 in ?? () #1 0x00000000004ad33e in display.Display.render() (this=0x7ffff7ecfe00) at source/dgame/display.d:95 #2 0x00000000004a01d5 in D main (args=...) at source/app.d:41 #3 0x00000000004cd9af in rt.dmain2._d_run_main() () #4 0x00000000004cd902 in rt.dmain2._d_run_main() () #5 0x00000000004cd968 in rt.dmain2._d_run_main() () #6 0x00000000004cd902 in rt.dmain2._d_run_main() () #7 0x00000000004cd883 in _d_run_main () #8 0x00000000004acfb5 in main () display.Display.render() is what tries to render the triangle using a glBegin-block.
Aug 29 2014
parent reply Mike Parker <aldacron gmail.com> writes:
On 8/29/2014 9:16 PM, Robin Schroer wrote:
 On Friday, 29 August 2014 at 11:51:47 UTC, Marc Schütz wrote:
 display.Display.render() is what tries to render the triangle using a
 glBegin-block.
Some code would be helpful. My first thought is that you aren't loading properly. DerelictGL3 does not load deprecated functions, but you're trying to call a deprecated function. Are you loading DerelictGL or DerelictGL3? --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Aug 29 2014
parent reply "Robin Schroer" <sulamiification gmail.com> writes:
On Friday, 29 August 2014 at 15:20:00 UTC, Mike Parker wrote:
 As the README in Derelict 3 points out, that project is no 
 longer updated. You should be using the binding from the 
 DerelictOrg project [1] for anything new.
 
 [1] https://github.com/DerelictOrg/
 
<stitch>
 On 8/29/2014 9:16 PM, Robin Schroer wrote:
 On Friday, 29 August 2014 at 11:51:47 UTC, Marc Schütz wrote:
 display.Display.render() is what tries to render the triangle 
 using a
 glBegin-block.
Some code would be helpful. My first thought is that you aren't loading properly. DerelictGL3 does not load deprecated functions, but you're trying to call a deprecated function. Are you loading DerelictGL or DerelictGL3?
So, I dug around a lot. I am using DerelictOrg, sorry if this was unclear, I was under the impression that it is still version 3. But anyway, I found out that some of my GL code is actually refering to null pointers because I have been using deprecated functions. So I am able to establish an OpenGL 3.3 context without crashing (although my test does not render yet, but that is another problem). Thank you to everyone nudging me in the right direction. -- Robin Schroer
Aug 30 2014
parent Mike Parker <aldacron gmail.com> writes:
On 8/30/2014 11:12 PM, Robin Schroer wrote:

 Some code would be helpful. My first thought is that you aren't
 loading properly. DerelictGL3 does not load deprecated functions, but
 you're trying to call a deprecated function. Are you loading
 DerelictGL or DerelictGL3?
So, I dug around a lot. I am using DerelictOrg, sorry if this was unclear, I was under the impression that it is still version 3. But anyway, I found out that some of my GL code is actually refering to null pointers because I have been using deprecated functions. So I am able to establish an OpenGL 3.3 context without crashing (although my test does not render yet, but that is another problem). Thank you to everyone nudging me in the right direction.
FYI, if you need the deprecated stuff it's all there. ``` // Modern GL only // import derelict.opengl3.gl3; // All of it, including the deprecated stuff import derelict.opengl3.gl; void loadGL() { DerelictGL.load(); DerelictGL.reload(); // Assuming a context is already created } ``` DerelictGL extends DerelictGL3, so it loads everything. --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Aug 30 2014
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Friday, 29 August 2014 at 11:23:34 UTC, Robin Schroer wrote:
 I'm not entirely sure where to post, so I will put it here.

 I'm playing around with D and Derelict 3 to make something with 
 OpenGL (don't really know what yet). I managed to open a 
 window, add an OpenGL context, clear the screen and flip 
 buffers. But as soon as I try to render a triangle, my program 
 crashes. I already tried hardcoding values in the shaders to 
 rule them out. I end up with:

 Error executing command run: Program exited with code -11

 Upon running with gdb, I get:

 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000000000 in ?? ()

 which is not really helpful to me.

 dub -v's output:

 [...]

 Full exception: 
 object.Exception source/dub/generators/build.d(405): Program 
 exited with code -11
 ----------------
 dub(pure  safe bool std.exception.enforce!(bool).enforce(bool, 
 lazy const(char)[], immutable(char)[], ulong)+0x6b) [0x67346f]
 dub(void 
 dub.generators.build.BuildGenerator.runTarget(dub.internal.vibeco
pat.inet.path.Path, 
 const(dub.compilers.compiler.BuildSettings), 
 immutable(char)[][])+0x4dc) [0x62db70]
 dub(void 
 dub.generators.build.BuildGenerator.generateTargets(dub.generators.generato
.GeneratorSettings, 
 const(dub.generators.generator.ProjectGenerator.TargetInfo[immutab
e(char)[]]))+0x231) 
 [0x62a75d]
 dub(void 
 dub.generators.generator.ProjectGenerator.generate(dub.generators.generator.Gener
torSettings)+0x2de) 
 [0x62f9a2]
 dub(void dub.dub.Dub.generateProject(immutable(char)[], 
 dub.generators.generator.GeneratorSettings)+0xaa) [0x5f1f46]
 dub(int dub.commandline.GenerateCommand.execute(dub.dub.Dub, 
 immutable(char)[][], immutable(char)[][])+0x677) [0x5e5b6b]
 dub(int dub.commandline.BuildCommand.execute(dub.dub.Dub, 
 immutable(char)[][], immutable(char)[][])+0x8d) [0x5e5e81]
 dub(int dub.commandline.RunCommand.execute(dub.dub.Dub, 
 immutable(char)[][], immutable(char)[][])+0x8d) [0x5e6041]
 dub(int 
 dub.commandline.runDubCommandLine(immutable(char)[][])+0x1211) 
 [0x5e3b8d]
 dub(_Dmain+0x20) [0x5e2334]
 dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).runAll().void __lambda1()+0x18) [0x6ce504]
 dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).tryExec(scope void delegate())+0x2a) 
 [0x6ce45e]
 dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).runAll()+0x30) [0x6ce4c4]
 dub(void rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).tryExec(scope void delegate())+0x2a) 
 [0x6ce45e]
 dub(_d_run_main+0x1a3) [0x6ce3df]
 dub(main+0x25) [0x5e2979]
 /lib64/libc.so.6(__libc_start_main+0xf5) [0x3dcae21d65]

 I am using the current master versions of Derelict, dub 0.9.21, 
 dmd v2.066.0, on Linux 3.15.7 x86_64

 I can post my source if needed, but it is quite a lot already. 
 I'm not really sure if it is my fault or a bug in Derelict or 
 dmd, hopefully someone is able to track this down.

 --

 Robin Schroer
Are you following this pattern?: // For core API functions. import derelict.opengl3.gl3; void main() { // Load OpenGL versions 1.0 and 1.1. DerelictGL3.load(); // Create an OpenGL context with another library (like SDL 2 or GLFW 3) ... // Load versions 1.2+ and all supported ARB and EXT extensions. DerelictGL3.reload(); // Now OpenGL functions can be called. ... } The "Segfault in ??" error is usually from calling a function pointer that hasn't been initialised, e.g. a more recent OpenGL api function that is only bound by calling DerelictGL3.reload();
Aug 29 2014
prev sibling next sibling parent reply "ponce" <contact gam3sfrommars.fr> writes:
On Friday, 29 August 2014 at 11:23:34 UTC, Robin Schroer wrote:
 I'm not entirely sure where to post, so I will put it here.

 I'm playing around with D and Derelict 3 to make something with 
 OpenGL (don't really know what yet). I managed to open a 
 window, add an OpenGL context, clear the screen and flip 
 buffers. But as soon as I try to render a triangle, my program 
 crashes.
As John Colvin said, forgetting to call DerelictGL3.reload() is a common error.
Aug 29 2014
parent reply "Robin Schroer" <sulamiification gmail.com> writes:
On Friday, 29 August 2014 at 12:41:38 UTC, ponce wrote:
 On Friday, 29 August 2014 at 11:23:34 UTC, Robin Schroer wrote:
 I'm not entirely sure where to post, so I will put it here.

 I'm playing around with D and Derelict 3 to make something 
 with OpenGL (don't really know what yet). I managed to open a 
 window, add an OpenGL context, clear the screen and flip 
 buffers. But as soon as I try to render a triangle, my program 
 crashes.
As John Colvin said, forgetting to call DerelictGL3.reload() is a common error.
I definitely reload after setting the context and before trying to render.
Aug 29 2014
parent Andrej Mitrovic via Digitalmars-d-learn writes:
On 8/29/14, Robin Schroer via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:
 I definitely reload after setting the context and before trying
 to render.
Typically these kinds of errors happen when a null function pointer is called. I'd add a few checks in some places to see what might have been left uninitialized.
Aug 29 2014
prev sibling parent Mike Parker <aldacron gmail.com> writes:
On 8/29/2014 8:23 PM, Robin Schroer wrote:
 I'm not entirely sure where to post, so I will put it here.

 I'm playing around with D and Derelict 3 to make something with OpenGL
As the README in Derelict 3 points out, that project is no longer updated. You should be using the binding from the DerelictOrg project [1] for anything new. [1] https://github.com/DerelictOrg/ --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Aug 29 2014