Jump to content
  • Advertisement
Sign in to follow this  
copacabana

Problem with isExtensionSupported

This topic is 5058 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got this procedure in my program it compiles but when it runs an error occures. Visual Studio.Net shows me some strstr.asm assembler file and points to some instruction. I haven't changed anything there so I believe it should work properly :P Why doesn't it?? I have copied whole procedure so an error has to have something to do with strstr but why?? Should I write my own strstr function? Maybe I'm doing something wrong ? Any ideas??

Share this post


Link to post
Share on other sites
Advertisement
based on the infomation given I'd say the answer to your question lies in the hidden kingdom of the StarElves, to get to it you must travels for 4 days by horse back over rocky terrain and face a trial of fire and ice.

or;
what code?
what error?

Share this post


Link to post
Share on other sites
Sorry for so few details. It's an mfc single document application that uses opengl. I'm trying to run isExtensionSupported to initialize my variable in class Doc in constructor for Doc class. I get something like this:

Unhandled exception at 0x10215c4e (msvcr71d.dll) in MyAppMR.exe: 0xC0000005: Access violation reading location 0x00000000.

and it directs me to strstr.asm to line:

mov al,[edi] ; al is next char from str1

Anybody knows what it means?? Maybe the elves do?? :)

Share this post


Link to post
Share on other sites
Unhandled exception at 0x10215c4e (msvcr71d.dll) in MyAppMR.exe: 0xC0000005: Access violation reading location 0x00000000

That seems something to do with uninitialized pointers!! ..
Probably somethning like :

char *temp;
strcpy(temp , "HI");

temp has not been allocated memory ..
Check out wether u have any bad pointers !! Or show me some code .. . may help


Share this post


Link to post
Share on other sites
This is the code of function that is causing trouble:

bool CMapReaderDoc::IsExtensionSupported(const char *szTargetExtension)
{
const unsigned char *pszExtensions;
const unsigned char *pszStart;
unsigned char *pszWhere=NULL, *pszTerminator;
pszWhere = (unsigned char *)strchr(szTargetExtension,' ');
if(pszWhere || *szTargetExtension == '\0')
return false;

pszExtensions = glGetString(GL_EXTENSIONS);

pszStart = pszExtensions;
for(;;)
{
pszWhere = (unsigned char *)strstr((const char *)pszStart, szTargetExtension);
if(!pszWhere)
break;
pszTerminator = pszWhere + strlen(szTargetExtension);
if(pszWhere == pszStart || *(pszWhere-1)==' ')
if(*pszTerminator == ' ' || pszTerminator == '\0')
return true;
pszStart = pszTerminator;
}
return false;

}

Share this post


Link to post
Share on other sites
See this to learn

http://www.devmaster.net/articles/opengl-extensions/

but use glee to use extensions without headache

http://elf-stone.com/downloads.php

Share this post


Link to post
Share on other sites
From the error you are clearly passing a null pointer to strstr. You probably want to validate the incoming string: szTargetExtension, you already check that it's not empty and doesn't have a space, might was well make sure it's not NULL. However if this was the problem you would probably see a crash at strchr().

My money is on the other string you are passing to strstr. According to msdn glGetString():

If an error is generated, glGetString returns zero.

You'll want to check that the string returned from glGetString is not NULL before you pass it on to strstr. If the call fails, you can check glGetError() to see what went wrong. Just a guess, but are you calling this before you have a valid ogl context?

I agree with the previous poster that you may want to consider using a 3rd party library to do extension loading for you, but I think writting this sort of thing yourself is a good learning exercise. Especially debugging the errors.

Just for future reference here are a few hints when debugging:

Look carefully at the exception generated. If it is trying to read or write to 0x00000000 then you need to look for a null pointer somewhere. Probably you either forgot to allocate memory or someone returned you a null pointer due to an error. If it is another address then it's a good chance you have an error calculating the size of an array, and you are outside the bounds. Also check that you have initialized your pointers (don't assume they will be NULL). If you are working with c style strings make sure they are nul terminated.

Also check if it is a read or write error. This will help you narrow down which array is the problem.

If the error is in library code it's almost always a problem with the params you passed in. Check them explicitly to make sure they are what you expect. A good debugger is your friend here. If you are using a value returned by another library function check the docs for that function, make sure it always returns valid data, and test for when it doesn't. If you are getting unexpected results see if the function sets an error value you can get. (Most opengl functions do).

Good luck :)

Share this post


Link to post
Share on other sites
Make sure you have a valid OpenGL context when calling glGetString. In other words, call it after the window where you do your OpenGL drawing is created.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!