View Full Version : Types of Cg error
MrIdiot
09-24-2005, 09:27 AM
i'm just starting trying to learn Cg. i put the following code to check for runtime compile errors:
if (!cgIsProgram(vertProgram))
MessageBox(NULL, cgGetErrorString(cgGetError()), "Cg runtime compilation failure", MB_OK|MB_ICONWARNING);
it there a way to get more detailed error information? it just says there was an error but it never gives any clue whats wrong.
thanks
MrIdiot
09-27-2005, 03:40 AM
am i asking this in the wrong forum or something? surely someone knows the answer?
NomadRock
09-27-2005, 05:10 AM
I've never used Cg, but instead use GLSL, however I can tell you that with languages like these, the error reporting is almost always very minimal.
Looking at that code though, It would look like GetErrorString should return a string that is specific to that error no? A quick google search tells me that is what you are supposed to do in order to get the error. I would suggest common debugging techniques for normal code, like reducing the complexity to the smallest program that still wont compile so you can narrow down the search for what you've done wrong.
Dia Kharrat
09-27-2005, 08:19 AM
If you run the Cg compiler from the command prompt and compile your shader, it should output the errors if there are any.
MrIdiot
09-28-2005, 06:12 AM
ok thanks for your help. NomadRock the GetErrorString function is not very helpful, it just says "the compile returned an error" but doesnt say what the error is. i will try compiling from the command prompt.
Kenneth Gorking
09-28-2005, 09:40 AM
The error you are getting means that there are syntax errors in your shader. I use this code to get more detailed info on the runtime errors/warnings:
// Error callback function for Cg
void __cdecl cgErrorCallback()
{
CGerror err = cgGetError();
if(err == CG_COMPILER_ERROR)
{
printf("*** Cg compiler error:\n%s\n", cgGetLastListing(g_cgContext));
}
else
{
const char* str = cgGetErrorString(err);///cgD3D9TranslateCGerror(err);
printf("%s", str);
HRESULT hres = cgD3D9GetLastError();
if(hres != S_OK)
{
const char* errStr = cgD3D9TranslateHRESULT(hres);
print(" - HRESULT: %s", errStr);
}
printf("\n");
}
}
...And then stick this call in your initialization:
cgSetErrorCallback(&cgErrorCallback);
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.