ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Clear Sky Forum » Mod discussion
Modified LuaJIT library

« Previous 10 events | 1 2 3 4 5 6 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  18:39:32  1 January 2014
profilee-mailreply Message URLTo the Top
Mac34
Senior Resident
 

 
On forum: 03/10/2013
Messages: 313
Thanks Xetrill. I'll give this a whirl, good luck with your work!
  02:21:46  3 January 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
Messages: 2230
Is it possible to add debugging features to the dll so that you retrieve a bit more info on a lua.jit.dll crash? For example I have someone experiencing a rare bug that crashes with:


0023:728CAEF3 lua.JIT.1.1.4.dll, lua_resume()

[error][ 298] : Too many posts were made to a semaphore.



I have no idea how to debug it, because it's intermittent. I was able to get my hands on a save where it supposedly happened 100% of the time for the tester but when I tried it, nothing happened.
  14:02:28  3 January 2014
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
 

Message edited by:
Xetrill
01/03/2014 14:04:41
Messages: 129
Yes, and it already does, to stdout. Since windows ignores the stdout/stderr streams be default (for non-console apps) you'll need to redirect those (stdout suffices, I'm not using stderr).

This is how, I launch the game:

@echo off
erase /f /q .\appdata\logs\*.mdmp
erase /f /q .\appdata\logs\Xs_*.log
.\bin\xrEngine.exe > .\appdata\logs\xrEngine.log


appdata is $app_data_root$ which I changed in fsgame.ltx, but that doesn't really matter.

Now, the added information comes in form of a Lua C stack dump, which represents the VM's state and the immediate code-path that lead to an error. It isn't the most obvious way to display that information, but it's what Lua actually processes.
"The Stack": http://www.lua.org/manual/5.1/manual.html#3.1

I'm not sure how much more info I can gather, Lua doesn't provide much facilities here. And worse yet, LuaJIT disables what is there (the hooking mechanism).
There is however _G.jit.debug().
Here's the relevant snippet from the LuaJIT's 1.1.8 documentation (which comes with the source code, AFAIK it's not available online anymore):

---QUOTATION---

jit.debug([level])

Set the debug level for JIT compilation. If no level is given, the maximum debug level is set.

Level 0 disables debugging: no checks for hooks are compiled into the code. This is the default when LuaJIT is started and provides the maximum performance.
Level 1 enables function call debugging: call hooks and return hooks are checked in the function prologue and epilogue. This slows down function calls somewhat (by up to 10%).
Level 2 enables full debugging: all hooks are checked. This slows down execution quite a bit, even when the hooks are not active.

Note that some compiler optimizations are turned off when debugging is enabled.

---END QUOTATION---



Other than that, I can tell you the error relates to Lua's coroutine library (specifically coroutine.resume). And that Lua/LuaJIT don't create any semaphores themselves, but they do create and use fibers (to implement coroutines).
I've never used fibers myself, so I can only guess that the error might be caused by either repeatably trying to resume an already resumed/running fiber or requesting the fiber to resume over and over and not waiting for it to actually happen.
Also it's most likely that game_object's event system (set_callback) is using fibers/coroutines.

Lastly, note that the debug version of the DLL spits out a lot more data (but it doesn't enter LuaJIT's debug mode -- jit.debug).
  23:28:52  3 January 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
01/03/2014 23:31:34
Messages: 2230

---QUOTATION---
Now, the added information comes in form of a Lua C stack dump, which represents the VM's state and the immediate code-path that lead to an error.
---END QUOTATION---



Can you explain how I dump that information to the log? The log is empty for me, do I need flush stdout?



---QUOTATION---
Other than that, I can tell you the error relates to Lua's coroutine library (specifically coroutine.resume). And that Lua/LuaJIT don't create any semaphores themselves, but they do create and use fibers (to implement coroutines).
I've never used fibers myself, so I can only guess that the error might be caused by either repeatably trying to resume an already resumed/running fiber or requesting the fiber to resume over and over and not waiting for it to actually happen.
Also it's most likely that game_object's event system (set_callback) is using fibers/coroutines.
---END QUOTATION---



Thank you, that is helpful. Seems to be related to when something dies or is shot. So I should look for any errors in the hit_callback or death_callback.
  00:10:53  4 January 2014
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
 

Message edited by:
Xetrill
01/04/2014 1:49:05
Messages: 129

---QUOTATION---
Can you explain how I dump that information to the log? The log is empty for me, do I need flush stdout?
---END QUOTATION---


No, just make sure you use the debug version (debug\bin\lua.JIT.1.1.4.dll), it will output data regardless if an error occurred or not, letting you know if it's working.

In the future I might add a launcher that captures stdout, but for now cmd.exe is good enough.

Update
New version up (link in signature) which passes all my test cases so far. I removed table.joinall since that was the cause of that odd error, I still don't get it...
Anyway, note that most of the table.* functions don't have test cases yet.

I've also enabled a atexit function/handler, which kinda works like it's C equivalent.
You can define a global function called 'atexit' and it gets called when Lua exists either cleanly or by error.
Its signature looks as follows: atexit(error_object, from_error, from_pcall).
error_object: is whatever was at the top of the stack (only relevant if from_error is true).
from_error: boolean; true if exiting due to an error false otherwise
from_pcall: boolean; true if Lua is in protected mode (by calling either pcall or xpcall) false otherwise.
I've included a sample implementation in common\scripts\_G.script:946.
The important thing about this function is, it gets called ALWAYS regardless of really anything. It doesn't matter if the game or luabind sets its own error handler.

This version also dumps the whole Lua library into the log to allow looking up function information.
  04:53:21  6 February 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
02/06/2014 4:58:07
Messages: 2230
Thanks Xetril. The guys at Epicstalker forums really appreciate this new version since it works for Call of Pripyat and has given good boost in FPS in Pripyat Reborn. Keep up the good work.

Also thanks for the tip about my crash. It was related to hear_callback.
  15:43:11  6 February 2014
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
Messages: 129
That's good to know, thanks.
It was me being overly pedantic, that caused the DLL not to work out of the box with CoP. I reverted to the default behavior, so it will just work now.

And to let everyone know, I'm still working on this project. Recently though, I've been pretty busy. That being said, I kinda miss this little project -- LuaJIT is quite a nice codebase to work with. Also there isn't all that much work needed to for a 1.0 release. I might get it done this or next weekend.

We'll see, cheers.
  17:05:45  6 February 2014
profilee-mailreply Message URLTo the Top
Bangalore
Robberbaron
(Resident)

 

 
On forum: 02/17/2008
 

Message edited by:
Bangalore
02/06/2014 17:07:13
Messages: 1159
Yeah, Xetrill, sorry for the pressure we do here , but since i discovered your posts in Smoq2's faction war topic, and first time in my life i succesfully compiled a binary file which works in COP, i became a huge fan of your dll's, so i started this thread in COP forum section:

https://www.gsc-game.com/index.php?t=community&s=forums&s_game_type=xr3&thm_page=69&thm_id=6030&sec_id=18&page=1

Thanks for your work again.
  16:00:41  16 February 2014
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
Messages: 129
New version is up, download link is in my signature.

The only notable change is that all my test cases pass.

I had hoped to get one additional feature ready (reusable persistent global mutable string buffers, same as LuaJIT 2) but couldn't yet figure out why my changes are causing a crash when exiting the game. Therefore, that's not in this build.

Now there's documentation to be written and profiling/tweaking to be done.
  23:39:28  16 February 2014
profilee-mailreply Message URLTo the Top
Decane
Senior Resident
 

 
On forum: 04/04/2007
Messages: 1706
Thank you, Xetrill. Your work is appreciated by many.
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Clear Sky Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2021 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.