Exception when adding const char* to std::string?
std::string APIVendor = (const char*)glGetString(GL_VENDOR);
This causes an exception in strlen.h recently but seems to work in older code... Any thoughts?
Thanks
Chris
Chris Brodie
I don''t want to embarrass myself, but have you tried this:
I don''t know that this is your problem, but glGetString returns an unsigned char* and your casting to a signed char*...
YAP-YFIO,
deadlinegrunt
std::basic_string<GLubyte> APIVendor = glGetString(GL_VENDOR);
I don''t know that this is your problem, but glGetString returns an unsigned char* and your casting to a signed char*...
YAP-YFIO,
deadlinegrunt
~deadlinegrunt
Code I wrote to show opengl info in msvc++ debugger window. Scroll down to see glGetString().
/*// Showing pixelformat info*/void COpenGL::ShowOpenGLInfo(HDC hDC){ // See what pixel format the computer chose for us PIXELFORMATDESCRIPTOR pfd = {0}; DescribePixelFormat(hDC, GetPixelFormat(hDC), sizeof(PIXELFORMATDESCRIPTOR), &pfd); int generic_format = pfd.dwFlags & PFD_GENERIC_FORMAT; int generic_accelerated = pfd.dwFlags & PFD_GENERIC_ACCELERATED; string str = ""; char arr[128] = ""; // generic_accelerated means it''s MCD that accelerates a subset of the // generic_format OpenGL implementation if(generic_format && !generic_accelerated) { // software str += "NO HARDWARE ACCELERATION\n"; } else { if(generic_format && generic_accelerated) { // hardware - MCD str += "HARDWARE MCD ACCELERATED\n"; } else { if(!generic_format && !generic_accelerated) { // hardware - ICD str += "HARDWARE ACCELERATED\n"; } } } str += "flags: "; if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) str += "PFD_DRAW_TO_WINDOW "; if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) str += "PFD_DRAW_TO_BITMAP "; if(pfd.dwFlags & PFD_SUPPORT_GDI) str += "PFD_SUPPORT_GDI "; if(pfd.dwFlags & PFD_SUPPORT_OPENGL) str += "PFD_SUPPORT_OPENGL "; if(pfd.dwFlags & PFD_GENERIC_ACCELERATED) str += "PFD_GENERIC_ACCELERATED "; if(pfd.dwFlags & PFD_GENERIC_FORMAT) str += "PFD_GENERIC_FORMAT "; if(pfd.dwFlags & PFD_NEED_PALETTE) str += "PFD_NEED_PALETTE "; if(pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE) str += "PFD_NEED_SYSTEM_PALETTE "; if(pfd.dwFlags & PFD_DOUBLEBUFFER) str += "PFD_DOUBLEBUFFER "; if(pfd.dwFlags & PFD_STEREO) str += "PFD_STEREO "; if(pfd.dwFlags & PFD_SWAP_LAYER_BUFFERS) str += "PFD_SWAP_LAYER_BUFFERS "; if(pfd.dwFlags & PFD_SWAP_COPY) str += "PFD_SWAP_COPY "; if(pfd.dwFlags & PFD_SWAP_EXCHANGE) str += "PFD_SWAP_EXCHANGE "; str += "\n\nversion:\t\t\t"; sprintf(arr, "%d", pfd.nVersion); str += arr; str += "\n"; str += "pixel type: "; if(pfd.iPixelType == PFD_TYPE_RGBA) str += "\t\tPFD_TYPE_RGBA"; else str += "\t\tPFD_TYPE_COLORINDEX"; str += "\n"; str += "color bits:\t\t\t"; sprintf(arr, "%d", pfd.cColorBits); str += arr; str += "\n"; str += "red bits:\t\t\t"; sprintf(arr, "%d", pfd.cRedBits); str += arr; str += "\tred shift:\t\t"; sprintf(arr, "%d", pfd.cRedShift); str += arr; str += "\n"; str += "green bits:\t\t"; sprintf(arr, "%d", pfd.cGreenBits); str += arr; str += "\tgreen shift:\t"; sprintf(arr, "%d", pfd.cGreenShift); str += arr; str += "\n"; str += "blue bits:\t\t\t"; sprintf(arr, "%d", pfd.cBlueBits); str += arr; str += "\tblue shift:\t\t"; sprintf(arr, "%d", pfd.cBlueShift); str += arr; str += "\n"; str += "alpha bits:\t\t"; sprintf(arr, "%d", pfd.cAlphaBits); str += arr; str += "\talpha shift:\t"; sprintf(arr, "%d", pfd.cAlphaShift); str += arr; str += "\n"; str += "depth buffer bits:\t\t"; sprintf(arr, "%d", pfd.cDepthBits); str += arr; str += "\n"; str += "stencil buffer bits:\t\t"; sprintf(arr, "%d", pfd.cStencilBits); str += arr; str += "\n"; str += "accum bits:\t\t"; sprintf(arr, "%d", pfd.cAccumBits); str += arr; str += "\n"; str += "accum red bits:\t\t"; sprintf(arr, "%d", pfd.cAccumRedBits); str += arr; str += "\n"; str += "accum green bits:\t\t"; sprintf(arr, "%d", pfd.cAccumGreenBits); str += arr; str += "\n"; str += "accum blue bits:\t\t"; sprintf(arr, "%d", pfd.cAccumBlueBits); str += arr; str += "\n"; str += "accum alpha bits:\t\t"; sprintf(arr, "%d", pfd.cAccumAlphaBits); str += arr; str += "\n"; if(pfd.iPixelType == PFD_TYPE_RGBA) str += "transparent RGB color value:\t"; else str += "transparent index color value:\t"; sprintf(arr, "%d", pfd.dwVisibleMask); str += arr; str += "\n\n"; // For the following the rendering context must exits first str += "opengl version:\t"; str += (char*)glGetString(GL_VERSION); str += "\n"; str += "vendor:\t\t"; str += (char*)glGetString(GL_VENDOR); str += "\n"; str += "renderer:\t\t"; str += (char*)glGetString(GL_RENDERER); str += "\n"; str += "opengl extensions:\t"; str += (char*)glGetString(GL_EXTENSIONS); OutputDebugString("\n*** OpenGL info ***\n"); OutputDebugString(str.c_str()); OutputDebugString("\n*** End ***\n\n"); }
Hello fellow OpenGL poets and lovers,
I am going to consider that for a moment perhaps your problem lies not in your code but in OpenGL, or perhaps your compiler. I have been a professional programmar for sometime now, and I have found that frequently bugs that I cannot fix actually lay in the compiler and thus I can do nothing about them.
I would strongly advise you to write a terse note to your compiler manufacturer explaining the defect and non-merchantability of their fine product, and demanding a full refund. That is what I do every time I come across these many compiler bugs.
Overjoyed at helping,
---
Fred Stumakas,
Professional Programmar
I am going to consider that for a moment perhaps your problem lies not in your code but in OpenGL, or perhaps your compiler. I have been a professional programmar for sometime now, and I have found that frequently bugs that I cannot fix actually lay in the compiler and thus I can do nothing about them.
I would strongly advise you to write a terse note to your compiler manufacturer explaining the defect and non-merchantability of their fine product, and demanding a full refund. That is what I do every time I come across these many compiler bugs.
Overjoyed at helping,
---
Fred Stumakas,
Professional Programmar
---Fred Stumakas,Professional Programmar
quote:
BS-BS-BS
BLAH-BLAH-BLAH
BS-BS-BS
Overjoyed at helping,
---
Fred Stumakas,
Professional Programmar
This troll right here is proof that natural selection doesn't work...
YAP-YFIO,
deadlinegrunt
Edited by - deadlinegrunt on January 3, 2001 11:06:03 PM
~deadlinegrunt
Hello Mr. Grunt,
I apologize if I have offended you. I was merely conveying my experiences as a professional programmar. I do not think that warranted personal attacks.
Happy to accept your apology,
---
Fred Stumakas,
Professional Programmar
I apologize if I have offended you. I was merely conveying my experiences as a professional programmar. I do not think that warranted personal attacks.
Happy to accept your apology,
---
Fred Stumakas,
Professional Programmar
---Fred Stumakas,Professional Programmar
quote: Original post by Fred Stumakas
Hello Mr. Grunt,
I apologize if I have offended you. I was merely conveying my experiences as a professional programmar. I do not think that warranted personal attacks.
Happy to accept your apology,
---
Fred Stumakas,
Professional Programmar
You''re not a professional programmer, you''re a fucking idiot. The problem isn''t the compiler, the problem is in the code.
gimp: You need to create and select a HGLRC to the HDC you pass in using SetPixelFormat, wglCreateContext, and wglMakeCurrent before calling any gl* functions.
MSN
quote: Original post by Fred Stumakas
I apologize if I have offended you. I was merely conveying my experiences as a professional programmar. I do not think that warranted personal attacks.
---
Fred Stumakas,
Professional Programmar
Listen up troll. You''ve been posting in nearly every forum now and before you could be avoided by your earlier screen names, but now you manage to become an even bigger nuisance by posting your nonsense in posts that others have made.
Any further replies from me to you will be via e-mail rather than in this forum, or on this site. I''d suggest you do the same. Better judgement tells me that I should use reverse psychology on you and beg you not to send me e-mail. What would it take? A dare? A double dare? Grow up troll...
Respectfully,
Mr. Grunt
Another Professional Programmer
~deadlinegrunt
Getting back on track...
I have a valid Opengl context when issuing this command. In fact the output of this command is sent back to my opengl console. Opengl is very much up and alive when I get this problem.
Normally I would just cut code to a small test app and test it there, but this SHOULD world and HAS worked, then I changed something in my configuration that made it stop working.
I use SDL to start opengl for me some most ogl initialization is done by SDL and hence isn''t something that I broke.
I find this really odd... I might try dumping it in to a char * on the heap and see if there is anything odd.
Many thanks
gimp
I have a valid Opengl context when issuing this command. In fact the output of this command is sent back to my opengl console. Opengl is very much up and alive when I get this problem.
Normally I would just cut code to a small test app and test it there, but this SHOULD world and HAS worked, then I changed something in my configuration that made it stop working.
I use SDL to start opengl for me some most ogl initialization is done by SDL and hence isn''t something that I broke.
I find this really odd... I might try dumping it in to a char * on the heap and see if there is anything odd.
Many thanks
gimp
Chris Brodie
quote: Original post by gimp
Getting back on track...
Good plan.
The only time I''ve found exceptions when initializing std::strings is when I try to assign them a null char pointer. std::string will throw access violation in this case:
char* p = NULL;
string s = p; // exception
Make sure the function cannot return NULL.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement