www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Should dmd have given me a warning at least?

reply "WhatMeWorry" <kc_heaser yahoo.com> writes:
// the following two lines compile cleanly but when executed, I 
get
// D:\Projects\Derelict>02_SimpleOpenGL_3_3_program.exe
// object.Error: Access Violation
// ----------------

string glShadingLangVer = 
to!string(glGetString(GL_SHADING_LANGUAGE_VERSION));
writeln("glShadingLangVer is ", glShadingLangVer);




glGetString has the following signature:

const GLubyte* glGetString(GLenum name);

I presume the const is causing the problem.  Is there a work 
around?

Thanks.
Sep 12 2014
next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 09/12/2014 03:44 PM, WhatMeWorry wrote:
 // the following two lines compile cleanly but when executed, I get
 // D:\Projects\Derelict>02_SimpleOpenGL_3_3_program.exe
 // object.Error: Access Violation
 // ----------------

 string glShadingLangVer =
 to!string(glGetString(GL_SHADING_LANGUAGE_VERSION));
According to the documentation, you are supposed to make sure that glGetString does not return 0: https://www.opengl.org/sdk/docs/man2/xhtml/glGetString.xml (See Notes and Errors there.)
 writeln("glShadingLangVer is ", glShadingLangVer);




 glGetString has the following signature:

 const GLubyte* glGetString(GLenum name);

 I presume the const is causing the problem.
No, const would have caused a compilation error. Access Violation is a runtime error caused by invalid memory access location like 0. ;) Ali
Sep 12 2014
parent reply "WhatMeWorry" <kheaser gmail.com> writes:
On Friday, 12 September 2014 at 22:53:35 UTC, Ali Çehreli wrote:
 On 09/12/2014 03:44 PM, WhatMeWorry wrote:
 // the following two lines compile cleanly but when executed, 
 I get
 // D:\Projects\Derelict>02_SimpleOpenGL_3_3_program.exe
 // object.Error: Access Violation
 // ----------------

 string glShadingLangVer =
 to!string(glGetString(GL_SHADING_LANGUAGE_VERSION));
According to the documentation, you are supposed to make sure that glGetString does not return 0: https://www.opengl.org/sdk/docs/man2/xhtml/glGetString.xml (See Notes and Errors there.)
 writeln("glShadingLangVer is ", glShadingLangVer);




 glGetString has the following signature:

 const GLubyte* glGetString(GLenum name);

 I presume the const is causing the problem.
No, const would have caused a compilation error. Access Violation is a runtime error caused by invalid memory access location like 0. ;) Ali
Isn't this a contradiction. The documentation says "glGetString returns a pointer to a static string..." But further on down it then says "If an error is generated, glGetString returns 0." This is the numeric value zero, right? So how can glGetString() return both a string and a zero? Btw, your book is excellent, Ali.
Sep 12 2014
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 09/12/2014 05:52 PM, WhatMeWorry wrote:

 Isn't this a contradiction.  The documentation says "glGetString
 returns a pointer to a static string..."
They are talking about a C string, which is normally a 'char*' (their API returns 'GLubyte*' but it doesn't matter here).
 But further on down it
 then says "If an error is generated, glGetString returns 0."
 This is the numeric value zero, right?

 So how can glGetString() return both a string and a zero?
In C (and C++ and D) numerical 0 is a placeholder for the null pointer value, whatever the actual null pointer value for that platform may be. (As far as I know, the actual null pointer value of all modern systems is also 0.) So, both are pointers: a C string is represented as a char* and 0 is the null pointer value. No contradiction there. I hope others with GL experience will answer your question.
 Btw, your book is excellent, Ali.
Thank you very much. :) Ali
Sep 12 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 9/13/2014 7:44 AM, WhatMeWorry wrote:
 // the following two lines compile cleanly but when executed, I get
 // D:\Projects\Derelict>02_SimpleOpenGL_3_3_program.exe
 // object.Error: Access Violation
 // ----------------

 string glShadingLangVer =
 to!string(glGetString(GL_SHADING_LANGUAGE_VERSION));
 writeln("glShadingLangVer is ", glShadingLangVer);




 glGetString has the following signature:

 const GLubyte* glGetString(GLenum name);

 I presume the const is causing the problem.  Is there a work around?

 Thanks.
Can you show more of your code so we can get some context? --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Sep 13 2014
parent "WhatMeWorry" <kheaser gmail.com> writes:
On Saturday, 13 September 2014 at 08:09:15 UTC, Mike Parker wrote:
 On 9/13/2014 7:44 AM, WhatMeWorry wrote:
 // the following two lines compile cleanly but when executed, 
 I get
 // D:\Projects\Derelict>02_SimpleOpenGL_3_3_program.exe
 // object.Error: Access Violation
 // ----------------

 string glShadingLangVer =
 to!string(glGetString(GL_SHADING_LANGUAGE_VERSION));
 writeln("glShadingLangVer is ", glShadingLangVer);




 glGetString has the following signature:

 const GLubyte* glGetString(GLenum name);

 I presume the const is causing the problem.  Is there a work 
 around?

 Thanks.
Can you show more of your code so we can get some context? --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Well, this morning on another system, the code works beautifully string glShadingLangVer = to!string(glGetString(GL_SHADING_LANGUAGE_VERSION)); writeln("glShadingLangVer is ", glShadingLangVer); returns glShadingLangVer is 4.20 - Build 10.18.10.3345 Thanks for you help.
Sep 13 2014