www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Access Violation while trying to use OpenGL

reply "spec00" <martins_ajc msn.com> writes:
I'am trying to play a bit with D and OpenGL by using the 
available Derelict bindings, but i'am even failing to create a 
window.

At the moment my code is as simple as:
-----------------------------------------
import derelict.glfw3.glfw3;

import std.c.stdio : fputs, fputc, stderr;

extern(C) nothrow void glfwPrintError(int error, const(char)* 
description) {
     fputs(description, stderr);
     fputc('\n', stderr);
}

void main() {
     DerelictGLFW3.load();

     glfwSetErrorCallback(&glfwPrintError);

     if(!glfwInit()) {
         glfwTerminate();
         throw new Exception("Failed to create glcontext");
     }
}
------------------------------------------

When i try to run it using dub i get the following:
{ test }  ยป dub run                                               
                                                                   
                                                                   
                 /c/git/opengl/test 2
Target derelict-util 2.0.3 is up to date. Use --force to rebuild.
Target derelict-glfw3 1.1.0 is up to date. Use --force to rebuild.
Target derelict-gl3 1.0.15 is up to date. Use --force to rebuild.
Building test ~master configuration "application", build type 
debug.
Compiling using dmd...
Linking...
Running .\test.exe
object.Error (0): Access Violation
----------------
0x001D1C61
0x0040204E in _Dmain at C:\git\opengl\test\source\main.d(15)
0x0041B262 in 
D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv
0x0041B237 in void rt.dmain2._d_run_main(int, char**, extern (C) 
int function(char[][])*).runAll()
0x0041B14B in _d_run_main
0x004184E4 in main
0x00430489 in mainCRTStartup
0x77C13744 in BaseThreadInitThunk
0x77DDA064 in RtlSetCurrentTransaction
0x77DDA02F in RtlSetCurrentTransaction
Error executing command run:
Program exited with code 1
----------------------------------

If i leave only the line DerelictGLFW3.load() it doesn't crashes.

I'am running windows 10 x64 and and dmd says: DMD32 D Compiler 
v2.068.0

Anyone has an idea of might be going on?

Thanks,
Sep 01 2015
parent reply "spec00" <martins_ajc msn.com> writes:
On Tuesday, 1 September 2015 at 20:15:28 UTC, spec00 wrote:
 I'am trying to play a bit with D and OpenGL by using the 
 available Derelict bindings, but i'am even failing to create a 
 window.

 [...]
The problem was in me using the 64bit version of the GLFW dll. DMD doesn't support compiling to x64? I tried using the DUB flag --arch=x86_x64 but i then got an error saying: Can't run '\bin\link.exe', check PATH What would be the correct way to compile to x64? Thanks,
Sep 01 2015
parent reply "Mike Parker" <aldacron gmail.com> writes:
On Tuesday, 1 September 2015 at 20:35:43 UTC, spec00 wrote:
 On Tuesday, 1 September 2015 at 20:15:28 UTC, spec00 wrote:
 I'am trying to play a bit with D and OpenGL by using the 
 available Derelict bindings, but i'am even failing to create a 
 window.

 [...]
The problem was in me using the 64bit version of the GLFW dll. DMD doesn't support compiling to x64? I tried using the DUB flag --arch=x86_x64 but i then got an error saying: Can't run '\bin\link.exe', check PATH What would be the correct way to compile to x64? Thanks,
To compile 64-bit programs on Windows, DMD requires the Microsoft toolchain. The easiest thing to do is to install the Community Edition of Visual Studio 2013 (DMD isn't yet compatible with VS 2015). Also, you aren't using OpenGL in this example, but GLFW :)
Sep 01 2015
parent reply "spec00" <martins_ajc msn.com> writes:
On Wednesday, 2 September 2015 at 01:07:01 UTC, Mike Parker wrote:
 On Tuesday, 1 September 2015 at 20:35:43 UTC, spec00 wrote:
 On Tuesday, 1 September 2015 at 20:15:28 UTC, spec00 wrote:
 [...]
The problem was in me using the 64bit version of the GLFW dll. DMD doesn't support compiling to x64? I tried using the DUB flag --arch=x86_x64 but i then got an error saying: Can't run '\bin\link.exe', check PATH What would be the correct way to compile to x64? Thanks,
To compile 64-bit programs on Windows, DMD requires the Microsoft toolchain. The easiest thing to do is to install the Community Edition of Visual Studio 2013 (DMD isn't yet compatible with VS 2015). Also, you aren't using OpenGL in this example, but GLFW :)
Thanks Mike!
Sep 02 2015
parent "ponce" <contact gam3sfrommars.fr> writes:
On Wednesday, 2 September 2015 at 18:31:32 UTC, spec00 wrote:
 On Wednesday, 2 September 2015 at 01:07:01 UTC, Mike Parker 
 wrote:
 To compile 64-bit programs on Windows, DMD requires the 
 Microsoft toolchain. The easiest thing to do is to install the 
 Community Edition of Visual Studio 2013 (DMD isn't yet 
 compatible with VS 2015).

 Also, you aren't using OpenGL in this example, but GLFW :)
Thanks Mike!
Don't forget to check your sc.ini file after that, and uncomment the relevant lines.
Sep 03 2015