# How to use HandleCgError?

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

## Recommended Posts

The below function is from the Cg Toolkit 1.4 manual:
void HandleCgError(CGcontext ctx, CGerror err, void *appdata)
{
fprintf(stderr, "Cg error: %s\n", cgGetErrorString(err));
const char *listing = cgGetLastListing(ctx);

if (listing != NULL)
fprintf(stderr, " last listing: %s\n", listing);
}


How and what do I supply as the third argument to HandleCgError? From another function I have tried: void someFun() { CGcontext m_context; m_context = Cg::context(); CGerror error; void* appdata; HandleCgError(m_context, error, appdata); } But then I get a Run-time check failure, saying that appdata is not initialized. I don't quite see that point in appdata since its not even used in HandleCgError.

##### Share on other sites
Quote:
 Original post by mltThe below function is from the Cg Toolkit 1.4 manual:*** Source Snippet Removed ***How and what do I supply as the third argument to HandleCgError? From another function I have tried:void someFun() {CGcontext m_context;m_context = Cg::context();CGerror error;void* appdata;HandleCgError(m_context, error, appdata);}But then I get a Run-time check failure, saying that appdata is not initialized. I don't quite see that point in appdata since its not even used in HandleCgError.
You can put whatever you want there, it's supposed to be used as an "extra" parameter, so you can pass data to your own HandleCgError handler. I'm not familiar with the Cg Toolkit, but usually you'd hand a pointer over to the API which will then get passed in to the error handler in the appdata parameter.
For instance, you could modify the HandleCgError function to fprintf to a FILE* instead of stderr, and pass the file handle to the API in whatever way you do it. Then, whenever there's an error, the HandleCgError function will be called, with the FILE* passed in the appdata parameter.

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633657
• Total Posts
3013197
×