I wanted to do some experimenting and add Lua scripting to my game engine just to see what the buzz was all about. So I created a test project, compile and everything worked first try. yay me \o/
Since it worked so well, what could go wrong ? So I try to include Lua in my game engine by reproducing the same step.
Compiling and linking without Lua = OK, Executing gives me the sweet job of seeing my game engine work
Compiling and linking with Lua but calling no lua function = OK, Executing works just as well
Compiling and linking with Lua and calling lua_open and lua_close = OK but Executing say it can't find msvcr80.dll
Weird I didn't to have it in my test project. So I copy the dll in my game engine folder. Oops !
Windows has triggered a breakpoint in HexEngine.exe.
This may be due to a corruption of the heap, and indicates a bug in HexEngine.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
The output window says :
'HexEngine.exe': Loaded 'C:\_Benoit\Development\HexEngine\Debug\HexEngine.exe', Symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\_Benoit\Development\HexEngine\lua5.1.dll', Binary was not built with debug information.
'HexEngine.exe': Loaded 'C:\_Benoit\Development\HexEngine\msvcr80.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\opengl32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\glu32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\ddraw.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\dciman32.dll', No symbols loaded.
First-chance exception at 0x7c90eae0 in HexEngine.exe: 0xC0000005: Access violation reading location 0x00000130.
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
Windows has triggered a breakpoint in HexEngine.exe.
This may be due to a corruption of the heap, and indicates a bug in HexEngine.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
First-chance exception at 0x7c964ed1 in HexEngine.exe: 0xC0000142: DLL Initialization Failed.
Unhandled exception at 0x7c964ed1 in HexEngine.exe: 0xC0000142: DLL Initialization Failed.
The only difference I can see between both projet is that one use main() the other WinMain()
Anybody with pointer that could help me debug this ?
Some code
TestLua
#include <stdio.h>
#pragma comment( lib, "./contrib/lua/lua5.1.lib" )
extern "C" {
#include "./contrib/lua/lua.h"
#include "./contrib/lua/lualib.h"
#include "./contrib/lua/lauxlib.h"
}
/* the Lua interpreter */
lua_State* L;
static int average(lua_State *L)
{
/* get number of arguments */
int n = lua_gettop(L);
double sum = 0;
int i;
/* loop through each argument */
for (i = 1; i <= n; i++)
{
/* total the arguments */
sum += lua_tonumber(L, i);
}
/* push the average */
lua_pushnumber(L, sum / n);
/* push the sum */
lua_pushnumber(L, sum);
/* return the number of results */
return 2;
}
int main ( int argc, char *argv[] )
{
/* initialize Lua */
L = lua_open();
/* load Lua base libraries */
luaL_openlibs(L);
/* register our function */
lua_register(L, "average", average);
/* run the script */
luaL_dofile(L, "test.lua");
/* cleanup Lua */
lua_close(L);
/* pause */
printf( "Press enter to exit..." );
getchar();
return 0;
}
HexEngine.h (lot of code removed)
// Link with the appropriate OpenGL's lib
#pragma comment( lib, "./contrib/lua/lua5.1.lib" )
#pragma comment( lib, "opengl32.lib" )
#pragma comment( lib, "glu32.lib" )
extern "C" {
#include "./contrib/lua/lua.h"
#include "./contrib/lua/lualib.h"
#include "./contrib/lua/lauxlib.h"
}
HexEngine.cpp
BOOL CHexEngine::initHexEngine()
{
window.setTitle("HexTesting");
/* the Lua interpreter */
lua_State* L;
/* initialize Lua */
L = lua_open();
/* load Lua base libraries */
luaL_openlibs(L);
lua_close(L);
return TRUE;
}
I'm using Visual C++ Express 2005 with PSDK installed. Don't hesitate to ask for more information :)
[Edited by - Tioneb on December 16, 2006 12:33:06 PM]