Author Topic: Question about linking / runtime errors building Glest 3.2.1 on Windows  (Read 3970 times)

WilyAdso

  • Guest
I followed the advice given on how to build Glest from source recently posted:

Compiling on Win32 using no-cost tools (MSVC++ 2008 Express)
https://forum.megaglest.org/index.php?PHPSESSID=5ad10f1271c8c746b8a970dd406c36b3&topic=3271.msg13807#msg13807

I was able to get the sources to compile with only warnings (mostly float/int conversion warnings) and also link.  However, when I try to execute the game, it immediately exits in Properties::load(const string &path).

I pulled up Windbg to see what was going on, and it appears that a call to malloc() in a basic_string constructor with size 4 causes malloc to call __crtExitProcess.

Is there something I'm doing wrong with the runtime initialization?  I'm building both the shared_library and the game with /MT (multithreaded) C runtime library.

Any help would be appreciated!

-Wily

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Perhaps you didn't copy the data files? So when it goes to load something that doesn't exist it crashes.
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

WilyAdso

  • Guest
Hi Hailstone,

Thanks for the response.

I copied over the executable to an installed glest directory which works with the precompiled version of the game.  The specific file it is trying to open when it calls Properties.load() is "glist.ini", which is in that directory, so I don't think the problem is that the file isn't present.

-Wily

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
On my machine it should be opening "glest.ini" not "glist.ini". I assume the dir is writable so that wouldn't be a problem. Can you get the exact line that is having the problem?
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

WilyAdso

  • Guest
Hi Hailstone,

Thanks for the reply.   That "glist.ini" was a typo in my earlier message.  The file on my machine is glest.ini as well.

In terms of what line of code is causing the error, I did the following.  In the first line of glestMain, I added the following line of code:

char *c = (char *) malloc(4);

This line of code causes malloc to terminate the program with error code 255.   I looked at the assembly code in malloc and here's what it looks like:

01699C9B  mov         edi,edi
01699C9D  push        ebp 
01699C9E  mov         ebp,esp
01699CA0  push        esi 
01699CA1  mov         esi,dword ptr [size]
01699CA4  cmp         esi,0FFFFFFE0h
01699CA7  ja          malloc+0B3h (1699D4Eh)
01699CAD  push        ebx 
01699CAE  push        edi 
01699CAF  mov         edi,dword ptr [__imp__HeapAlloc@12 (1918A20h)]
01699CB5  cmp         dword ptr [__crtheap (19156B8h)],0
01699CBC  jne         malloc+3Bh (1699CD6h)
01699CBE  call        @ILT+86470(__FF_MSGBANNER) (14D91CBh)
01699CC3  push        1Eh 
01699CC5  call        @ILT+13195(__NMSG_WRITE) (14C7390h)
01699CCA  push        0FFh
01699CCF  call        @ILT+35970(___crtExitProcess) (14CCC87h)
01699CD4  pop         ecx 
01699CD5  pop         ecx 
01699CD6  mov         eax,dword ptr [___active_heap (1915F08h)]

It looks like the following test is failing in my excutable, causing the code the fall through to the ___crtExitProcess
01699CAF  mov         edi,dword ptr [__imp__HeapAlloc@12 (1918A20h)]
01699CB5  cmp         dword ptr [__crtheap (19156B8h)],0
01699CBC  jne         malloc+3Bh (1699CD6h)

Any ideas why it would fail?

Thanks,

-Wily

WilyAdso

  • Guest
Okay - I worked this one out finally.  The problem was the I had specified the entry point in Visual Studio in the "Linker|Advanced|Entry Point" tab to be "main" when I should have specified it to be mainCRTStartup.

Because it wasn't executing the CRT startup code, the first time I called the malloc, the runtime failed.

Thanks for your help!

-Wily

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
It's good you have it working. Any reason why you are using malloc?
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

WilyAdso

  • Guest
I wasn't calling malloc directly, but all the calls to "new" in C++ end up calling down to malloc eventually.  So the C runtime has to be initialized correctly for the game to work.

-Wily