Jump to content
  • Advertisement
Sign in to follow this  
aayudh

is multiple lua_open possible ?

This topic is 3606 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

wish you a happy new year !! but i got a question... [this is for my app in windows] i am getting some magical crash at this line in free.c retval = HeapFree(_crtheap, 0, pBlock); In my app, the .exe project created a lua state and maintains the game scripts. In my server.dll and client.dll (seperate projects), i have another lua state which maintains the network scripts (what, how, when to communicate stuff). I thought I was doing something bad in lua, but I found this line , >As of Lua 5.0, this configuration is not supported; you may only have one instance of liblua in a given execution image. in >http://lua-users.org/wiki/LuaFaq Does this mean my setup is bad ? I was always assuming the lua stacks were seperate and not related ? I am shocked. Someone help me please !!!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by aayudh
Does this mean my setup is bad ? I was always assuming the lua stacks were seperate and not related ?


The stacks are indeed not related, however it looks like the lua library does something on initalisation which, when you try to effectively load multiple instances of the library at once causes problems.

As Kambiz says, if you want to link lua to multple dlls independantly then you'll need to use dynamic linking and keep the lua library in a dll/so.

Share this post


Link to post
Share on other sites
actually I am using lua5.1_dll-d.lib for debug testing...yes, I am using the dll of lua in both .exe project and server.dll project.

You think i should link lua statically ?

Share this post


Link to post
Share on other sites
The FAQ says that this problem happens when you create an executable with two copies of liblua. Maybe you are linking to the release versions in server.dll and debug version in exe or something similar.

EDIT: Are you linking to liblua while building server.dll? I'm not sure about Windows, but under Linux this is not necessary as long as you link to all required libraries when building the executable.

Quote:
Original post by aayudh
You think i should link lua statically ?

No.

[Edited by - Kambiz on December 27, 2008 10:34:17 AM]

Share this post


Link to post
Share on other sites
hey,

lua5.1_dll-d.lib is compiled as static lib using /MDd . Sorry about that. This means I am linking to a static lib right ?

I verified and there is no mix up between debug and release stuff. But I am using this static lib both in the .exe and .dll project.

So you want me to change it to be compiled down as a .dll project ?

[Edited by - aayudh on December 27, 2008 11:48:58 AM]

Share this post


Link to post
Share on other sites
hey guys,


its a very subtle bug as it appears randomly.

But I have tested it more than before and its not popping up :) Basically I followed as you said and make the lua in a dll instead of a static lib.

You guys are amazing !!! Thanks Kambiz and Phantom.

Can you tell me what was going on ? I mean why if it is a static lib it can cause such a problem and why when its a dll that problem is solved? What was the problem ??

Share this post


Link to post
Share on other sites
My limited DLL knowledge make me think you have two copies of lualib in your project (one in the DLL and one in the exe). I believe there are static variables in the lua library that it uses, with two copies of the static data around it blows up. Putting the lua lib in a a DLL forces it to load only one copy of the library, any subsequent requests will reference the first DLL and the problem goes away.

Cheers,

Bob

Share this post


Link to post
Share on other sites
Quote:
Original post by aayudh
hey,

lua5.1_dll-d.lib is compiled as static lib using /MDd . Sorry about that. This means I am linking to a static lib right ?


Yes.

Quote:
I verified and there is no mix up between debug and release stuff. But I am using this static lib both in the .exe and .dll project.

So you want me to change it to be compiled down as a .dll project ?


Definitely. I got similar issues in my engine (currently linux only) when I split it into shared objects (ie dlls). I had to compile lua as a shared object too so that its code wouldn't be duplicated within my process. Some of the lua objects rely on static variables and you get all kind of nasty problems if said variables aren't unique within the process (ie if you have the lua code twice in two different place).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!