global static pointer variable in DLL

torhu no at spam.invalid
Sun May 25 10:59:39 PDT 2008


Zarathustra wrote:
> torhu Wrote:
> 
>> Zarathustra wrote:
>> > 
>> > Oh, I find out something.
>> > The most crashes occur in similar calls (in DLL) like following:
>> > ________________________________________________________
>> > offs += fprintf(gl2ps->stream, "%%PDF-1.4\n");
>> > ________________________________________________________
>> > it looks like DLL haven't got access to FILE(gl2ps->stream), but why?
>> > The FILE is operand of gl2psBeginPage.
>> > Call of gl2psBeginPage function in my D code is in following function:
>> > ________________________________________________________
>> > extern (C) void
>> > SaveFile(){
>> > 	FILE* fp;
>> > 	int state = GL2PS_OVERFLOW;
>> > 	int buffsize = 0;
>> >             		
>> > 	try{
>> > 		fp = fopen("out.pdf", "wb");
>> > 		while(state == GL2PS_OVERFLOW){
>> > 			buffsize += 1024*1024;
>> > 
>> > 			gl2psBeginPage(
>> > 				"test", 
>> > 				"gl2psTestSimple", 
>> > 				null, 
>> > 				GL2PS_PDF, 
>> > 				GL2PS_SIMPLE_SORT,
>> > 				GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT,
>> > 				GL_RGBA, 
>> > 				0, 
>> > 				null, 
>> > 				0, 
>> > 				0, 
>> > 				0, 
>> > 				buffsize, 
>> > 				fp, 
>> > 				"out.pdf"
>> > 			);
>> > 			
>> > 			RenderFrame();
>> > 			state = gl2psEndPage();
>> > 		}
>> > 		fclose(fp);
>> > 		MessageBoxA(null, "File saved", "Information", MB_OK | MB_ICONINFORMATION);
>> > 	}
>> > 	catch(Object o){
>> > 		MessageBoxA(null, cast(char*)o.toString(), "Critical Error", MB_OK | MB_ICONERROR);
>> > 	}
>> > }
>> > ________________________________________________________
>> > exactly: gl2ps->stream = fp;
>> > 
>> 
>> Have you tried debugging this code with ddbg, and checked what the 
>> actual values of gl2ps and gl2ps->stream are when it crashes?
>> 
>> http://ddbg.mainia.de/
> 
> I converted all gl2ps code to d and then started debugging with ddbg.
> I have got a problem with allocating memory. I have got the following code:
> 
> if(gl2ps.bgcolor is cast(GL2PSrgba*)null){
>     gl2ps.bgcolor = cast(GL2PSrgba*)malloc(GL2PSrgba.sizeof);
> }
> 
> and error:
> Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at ?Alloc at RTLPool@@QAEPAXXZ (0x0042e8a9) thread(5368)
> 
> I don't know what does it mean.
> 
> 

Does it crash on the malloc line?  Maybe you've got heap corruption. 
You could check for stray pointers or buffer overflows.  Maybe someone 
else recognizes this error and can tell you more, because I might be 
completely wrong about this.


More information about the Digitalmars-d-learn mailing list