Windows program instant crash: no messages.

Nekroze nekroze at eturnilnetwork.com
Tue Jun 12 02:59:24 PDT 2012


On Tuesday, 12 June 2012 at 09:03:43 UTC, Andrew Wiley wrote:
> On Tue, Jun 12, 2012 at 1:50 AM, Andrew Wiley 
> <wiley.andrew.j at gmail.com> wrote:
>> On Tue, Jun 12, 2012 at 1:32 AM, Dmitry Olshansky 
>> <dmitry.olsh at gmail.com> wrote:
>>> On 12.06.2012 11:17, Nekroze wrote:
>>>>
>>>> Hello. I am trying to make a wrapper to use the DarkGDK 3d 
>>>> game engine
>>>> for windows with D and i am doing rather well so far. I have 
>>>> just gotten
>>>> it to successfully compile however the resulting exe 
>>>> instantly crashes
>>>> and outputs nothing at all even though the very first 
>>>> command in WinMain
>>>> is writeln which doesnt show up.
>>>
>>>
>>> It may be the case that you need to call rt_init(); at first 
>>> line of
>>> WinMain. Every time I see WinMain problems it boils down to D 
>>> runtime not
>>> setup properly.
>>
>> I agree. Take a look at http://dlang.org/windows.html
>> Working from that, I was able to get your app to begin to 
>> start up.
>> The other trick is that when you structure your main this way,
>> stdout/stderr/stdin don't seem to be set up for you (at least, 
>> not
>> with MinGW GDC). I added this:
>> stdout = File("test.txt", "w");
>>
>> and now test.txt contains this:
>> %sCreating Swindow
>> %sInitializing DarkGDK
>>
>> It's still crashing, but it's getting significantly farther. I 
>> haven't
>> dug enough to figure out what's going on now.
>
> Actually, it's not crashing, it's failing to initialize DarkGDK 
> and
> bailing nicely. Looks like it's probably because the DarkGDK 
> DLL is 32
> bit and I'm building a 64 bit executable.
>
> If I switch to a 32 bit executable and add a stdout.flush() 
> after
> every writeln, I get this:
> %sCreating Swindow
> %sInitializing DarkGDK
> %sStarting the window
> %sHanind the window to DarkGDK
>
>
> Unfortunately, I can't debug the crash for some reason. I'll 
> have to
> ping the MinGW GDC folks about it.
>
> The code looks like this: http://pastebin.com/i5A3PFTt
> My GDC build.bat looks like this: http://pastebin.com/PW30V3q4

Great, thanks for the help so far. I have altered some of the 
code for main.d and simplewindow.d to incorporate these tips. 
Mainly i have offloaded WinMain to simpleWindow.d and made it 
call GDKmain which is my new main(post WinMain) function in the 
main.d i had wanted to do this originally as i didn't like making 
the end-user have to have a WinMain with all these args that they 
don't need for this engine and the need to export windows. There 
may be issues with doing this later on but for the moment i like 
it this way except for the fact that showWindow in GDKmain needs 
the nCmdShow from WinMain so i have to pass that along to it 
still.

I have also reordered the way things are called in main.d so that 
things make more sense, so it tries to initialize the dll (and 
fails) then starts creating the window, you don't want a window 
just sitting there blank and non responsive while the dll 
initializes so thats what i have done.

Yes the dll is 32bit, i am just using plain dmd and haven't had 
any problems as i believe its just doing 32bit as i wanted it to.

I did actually have the runtime initialization in the 
Swindow.start but i guess it has to be a part of WinMain to work.

I just replaced the file at the previous download link in the OP 
so if you re-download from there you get the new version with the 
adjustments. also i added kernel32.lib to the build as 
MonoDevelop seems to do that so i thought i should too.

Thanks for the help so far guys, cant wait to get this to work!



More information about the Digitalmars-d-learn mailing list