Jazzle
asked on
Annoying: Access Violation / Null Reference
Hi Experts,
I have a C# application that calls a DLL written by me in C++.
GPGUI.exe calls gpmain() in simplegpdll.dll with the following line:
if (simplegpdll.gpmain(...,.. .,...) == 1) {... return true;}
Most of the time it runs with no problems - however, sometimes (and I can't spot a pattern), it crashes with the following error:
First-chance exception at 0x77f5b2ab in GPGUI.exe: 0xC0000005: Access violation reading location 0x00000034.
An unhandled exception of type 'System.NullReferenceExcep tion' occurred in simplegpdll.dll
Additional information: Object reference not set to an instance of an object.
The DLL reads a text file, and writes three (once each per operation). All reads and writes look like this:
FILE *solstream;
solstream=fopen("solution. csv","w+") ;
fprintf(solstream,"Gen,Bes t Program\n%d,%d\n", generation, best_prog);
fclose(solstream);
fcloseall();
Any suggestions on what's at 0x00...34 (or how to find out), and also what is throwing the Null Ref?
Thanks in advance, J
I have a C# application that calls a DLL written by me in C++.
GPGUI.exe calls gpmain() in simplegpdll.dll with the following line:
if (simplegpdll.gpmain(...,..
Most of the time it runs with no problems - however, sometimes (and I can't spot a pattern), it crashes with the following error:
First-chance exception at 0x77f5b2ab in GPGUI.exe: 0xC0000005: Access violation reading location 0x00000034.
An unhandled exception of type 'System.NullReferenceExcep
Additional information: Object reference not set to an instance of an object.
The DLL reads a text file, and writes three (once each per operation). All reads and writes look like this:
FILE *solstream;
solstream=fopen("solution.
fprintf(solstream,"Gen,Bes
fclose(solstream);
fcloseall();
Any suggestions on what's at 0x00...34 (or how to find out), and also what is throwing the Null Ref?
Thanks in advance, J
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, so I have now found that the exception is caused by the fprintf() command - so i suppose it's refering to the file i want to write to. all the files written to are closed afterwards - so could it be a matter of threads confusing each other? (I haven't specifed any thread usage)
************* Exception Text **************
System.NullReferenceExcept ion: Object reference not set to an instance of an object.
at fprintf(_iobuf* , SByte* )
at gpmain(Int32 POPULATION_SIZ.....
************* Exception Text **************
System.NullReferenceExcept
at fprintf(_iobuf* , SByte* )
at gpmain(Int32 POPULATION_SIZ.....
ASKER
You were right it seems the fopen() command is sometimes returning NULL - but I can't see why - any ideas anyone?
J
J
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks - will look into GetLastError().
ASKER
also, I know that solstream can't be null because of the way it's created.
I did wonder about file sharing, but i have found found that it gives a different error if the file is in use.
thanks for looking.
J
PS - 'hth'?