Hard Light Productions Forums

General FreeSpace => FreeSpace & FreeSpace Open Support => Topic started by: Askahain on October 14, 2015, 04:52:14 am

Title: 3.7.2 + lua socket crashes
Post by: Askahain on October 14, 2015, 04:52:14 am
Hello,

a few days ago i tried to use the 3.7.2 exe for my fs2.

Unfortunately the game crashes but the debug log tells me nothing about the crash. :(

Code: [Select]
.
.
.
cfile_init() took 81
TrackIR Init Failed - 1
Got event GS_EVENT_GAME_INIT (49) in state NOT A VALID STATE (0)
PLR => Loading 'Askahain.plr' with version 2...
PLR => Parsing:  Flags...
PLR => Parsing:  Info...
PLR => Parsing:  Scoring...
PLR => Parsing:  ScoringMulti...
PLR => Parsing:  HUD...
PLR => Parsing:  Variables...
PLR => Parsing:  Multiplayer...
PLR => Parsing:  Controls...
PLR => Parsing:  Settings...
Someone passed an extension to bm_load for file 'thunderlords.pcx'
PLR => Loading complete!
PLR => Verifying 'Askahain.plr' with version 2...
PLR => Parsing:  Flags...
PLR => Parsing:  Info...
PLR => Verifying complete!
After a little bit of testing i found the problem that caused the crash but i don't know why.

The problem was in the scripting tables. I have a modular table that opens a lua socket
Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On State Start:
[
socket=require("socket")
]
#End
if i comment this line the game works. if i don't the game crashes.

In 3.7.1 it works without any problem and if i try it with lua on the command line it is still no problem
Code: [Select]
D:\Spiele\Diaspora>lua5.1.exe
Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
> socket = require("socket")
> print(socket._VERSION)
LuaSocket 2.0.2
>

Can somebody give me a hint why the luasocket won't work with the 3.7.2 exe ?

With kind regards

Askahain
Title: Re: 3.7.2 + lua socket crashes
Post by: AdmiralRalwood on October 14, 2015, 02:38:22 pm
Does it still not work with a recent Nightly Build (http://www.hard-light.net/forums/index.php?board=173.0)?
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 14, 2015, 02:57:47 pm
I'm a bit surprised that it worked with 3.7.1, the internet says that lua needs to be linked dynamically in order to load an external DLL but we currently link lua statically into our executable.
Did our build process change in some way since 3.7.1?
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 15, 2015, 03:46:37 am
I tested it with the Version "fs2_open_3_7_3_SSE_20151006_61f2e78.exe" (nightly build) and it don't work.

but i have tested many nightly builds to find the last working version.

The last working version was r10753 the next version (don't working) was r10758

as far as i can see in the change log there was a change in release 10756
[Added multiple scripting features related to messaging as requested by Axem.] by m_m

Maybe there where changed something that cause the crash. I hope somebody can help with this because it will take weeks for me to understand the many changes in c code :)

With kind regards

Askahain

P.s. i get luasocket from this page http://files.luaforge.net/releases/luasocket/luasocket (Version 2.0.2) (if somebody will test it)
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 20, 2015, 02:53:04 am
Hmm, anyone who can help with this ?
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 20, 2015, 04:21:05 am
Sorry for the delay :nervous:

First, thanks for narrowing down the revision range. That should help tracking down what's the issue here.

As you mentioned the only scripting related change was done by me but as far as I can tell it shouldn't affect how lua loads external modules at all.

You mentioned that FSO would "crash". What do you mean by that? Does it show the usual "FreeSpace Open has stopped working" dialog or is there a dialog generated by FSO (you might habe to run a debug build to check this as only those show all warning messages)?
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 20, 2015, 10:54:20 am
Hello,

here is a screenshot of the crash.
(http://battlestar.askahain.de/DonwloadOpen/fs2-udp-crash-r10758.jpg)

Here are the configure debug_filters
Code: [Select]
+General
-Parse
+OpenAL
+SHADER-DEBUG
+Error
+BmpMan
+Paging
+Network
+Sandeep
+BmpFastLoad
+Sound
+Maps
+Model
+SEXP
+Warning
+wash
+AB TRAIL
+Weapons
+BmpInfo
+BMP DEBUG
+Alan
+lethality
+Joystick
+Particles
+AI
+ModelAnim
+Messaging
+Beam
+Physics
+allender
+CSG
+Fred routing
+EVENTMUSIC
+OpenGL
+missionlog
+Jim
+lightning
+CFileDebug

Here is (very long) the fs2_open.log http://battlestar.askahain.de/DonwloadOpen/fs2_open.log (http://battlestar.askahain.de/DonwloadOpen/fs2_open.log)

Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 20, 2015, 02:41:56 pm
mjn.mixael tested the script with the latest git version but everything worked properly but there is one thing you might try. In the download of luasocket you linked to there is a file valled "lua5.1.dll". Can you try extracting that to the directory of the FSO executable you are using?
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 21, 2015, 06:06:07 am
Ok now its very strange.

Testresult: Freespace 2 SCP 3.7.3(20151006) is working / Diaspora 3.7.3(20151006) isn't working.

What i have done:

I have installed Diaspora on a new system. Patched Diaspora to 1.1. Patched Diaspora to 1.1.1.
Copied the luasocket to the directory.
Code: [Select]
+ Disporadir
| lua5.1.exe
|  lua5.1.dll
+ mime
|  | core.dll
+ socket
|  | core.dll
+ lua
   | socket.lua
   | ltn12.lua
   | mime.lua
   + socket
      | ftp.lua
      | http.lua
      | smtp.lua
      | tp.lua
      | url.lua

Copied fs2_open_3_7_3_SSE_20151006_61f2e78.exe to the Diaspora dir.

Diaspora is working

Copied udp-sct.tbm in the table dir
Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On State Start:
[
socket=require("socket")
]

#End

Diaspora Crashes

---------------------------------------
Next test with Freespace 2

Installed Freespace 2 with the automatic install tool. (FS2 Open + MediaVP, no mods)

Copied luasocket to the Freespace 2 dir (same as above)

Copied fs2_open_3_7_3_SSE_20151006_61f2e78.exe to the Diaspora dir.

Copied udp-sct.tbm in the table dir

Freespace 2 is working (no crash).

I will now check what the difference between the two installations is. I will report what the result is.

Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 21, 2015, 06:31:03 am
Hello,

i think i have found the part that crashes the game.

The problem is found in diaspora patch 1.1.1. If i delete the patch everything works fine.

So what have change with the patch ? In the patch is 1 tbm and 2 missions.

A little bit try an error in the tubeLaunch-sct.tbm an i found the point an which the game crashes.

The script have a Global Hooks section
Code: [Select]
#Global Hooks
$Simulation:
[
if (tubeLaunches ~= nil) then
    tubeLaunches:onFrame()
end
]
#End

if i comment this section the game don't crashes. After a little bit of testing it shows that the $Simulation part is the problem.

This works
Code: [Select]
#Global Hooks

#End

This don't work
Code: [Select]
#Global Hooks

$Simulation:
[
]
#End

The question is why crashes the "$Simulation" Section the game if i "require" the luasocket since version r10758.

I hope this helps to find the problem. (If you need more or more detailed information please ask)

With kind regards

Askahain
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 21, 2015, 06:52:40 am
That's certainly very intersting and means that something is broken inside FSO. I'll try to reproduce the crash on my computer later today, if it's a cross-platform issue then tracking it down shouldn't be hard.  Does it also crash if you only use retail data (+ the two script files)?
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 21, 2015, 07:40:15 am
On the retail version i can't reproduce the error with the two scripts.

But i have found some other interesting part.

As i get back the original version of the script i see that the block is multi line commented.

Code: [Select]
;--[[
;; General Documentation:
;; This script supports the launch from a moving and even turning battlestar. There are some issues when the battlestar is accelerating where a small displacements is observable but once the ship has reached a given speed this disappears.

#Global Hooks

$Simulation:
[
if (tubeLaunches ~= nil) then
    tubeLaunches:onFrame()
end
]
;]]

#End

So there are two funny things
1. There should be a problem because the "Global Hooks" Section is commented but the "#End" Section isn't. So there is a end section without a start section. (On my test i accidentally repaired this).

2. If i implement a mistake in the commented code (for example changed "~=" to "~x=" the game generates me a scripting error. Is there maybe a problem with the comments, too ?
Title: Re: 3.7.2 + lua socket crashes
Post by: AdmiralRalwood on October 21, 2015, 02:55:36 pm
On the retail version i can't reproduce the error with the two scripts.

But i have found some other interesting part.

As i get back the original version of the script i see that the block is multi line commented.

Code: [Select]
;--[[
;; General Documentation:
;; This script supports the launch from a moving and even turning battlestar. There are some issues when the battlestar is accelerating where a small displacements is observable but once the ship has reached a given speed this disappears.

#Global Hooks

$Simulation:
[
if (tubeLaunches ~= nil) then
    tubeLaunches:onFrame()
end
]
;]]

#End

So there are two funny things
1. There should be a problem because the "Global Hooks" Section is commented but the "#End" Section isn't. So there is a end section without a start section. (On my test i accidentally repaired this).

2. If i implement a mistake in the commented code (for example changed "~=" to "~x=" the game generates me a scripting error. Is there maybe a problem with the comments, too ?
The "problem" here is that those Lua comment blocks are themselves... commented out (notice the semicolons). They don't actually make sense outside of a hook anyway. If you wanted to comment out the entire hook, you'd need to use FSO's multi-line comment syntax, which is either "/*" and "*/", or "!*" and "*!" (either style works, but you can't intermix the two).
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 22, 2015, 05:34:49 am
Ok thank you for this information about the comments. I will send it to the Diaspora Team. This is one of their scripts.
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 22, 2015, 05:39:14 am
It's actually my script which I created for Diaspora. I think I added that comment to make my editor stop complaining about the tables syntax in a lua file.
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 22, 2015, 06:07:28 am
Oh, ok sorry :)
Then ignore the post in the Diaspora Tech forum :)
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 22, 2015, 06:33:05 am
Just to explain why the luasocket and diaspora is so important for me.
This are the parts that running my vipercockpit V1. At the moment i try plan a cockpit v2 (to remove all the mistakes i made and make it nicer an more functional) but for this all systems should run fine :)

Picture from Cockpit V1 inside:
(http://battlestar.askahain.de/bilder/viper/IMAG1899-small.jpg) (http://battlestar.askahain.de/bilder/viper/IMAG1899.jpg)

More Pictures: http://larptech.de/index.php?S=viperbau
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 24, 2015, 07:49:06 am
Ok, I got around to testing it on my machine but I sadly can't reproduce the issue and I also don't have a Windows install at the moment.

I'll see if I can get someone on Windows to test this.
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 24, 2015, 11:52:57 am
Ok thank you very much.

If i can help you with something just tell me.

With kind regards

Askahain
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 24, 2015, 11:58:09 am
Well, if you want to install Visual Studio you could try following this guide (http://www.hard-light.net/wiki/index.php/What_to_do_when_SCP_coders_cannot_reproduce_your_fs2_open_crashes%3F) which would give me an indication where FreeSpace is crashing.
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 26, 2015, 02:23:48 am
Ok i will try this and report here.
Title: Re: 3.7.2 + lua socket crashes
Post by: Askahain on October 26, 2015, 04:19:54 am
Hello,

i hope i have done this the right way.

Here is the text of the "stack"-tab

Code: [Select]
lua5.1.dll!0f1dec49() Unbekannt
  [Unten angegebene Rahmen sind möglicherweise nicht korrekt und/oder fehlen, keine Symbole geladen für lua5.1.dll]
  lua5.1.dll!0f1e00fd() Unbekannt
  lua5.1.dll!0f1d1d88() Unbekannt
  lua5.1.dll!0f1e2477() Unbekannt
  core.dll!0ca21011() Unbekannt
  core.dll!0ca23085() Unbekannt
  core.dll!0ca224f0() Unbekannt
> fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_precall(lua_State * L, lua_TValue * func, int nresults) Zeile 320 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_call(lua_State * L, lua_TValue * func, int nResults) Zeile 377 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!lua_call(lua_State * L, int nargs, int nresults) Zeile 782 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!ll_require(lua_State * L) Zeile 484 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_precall(lua_State * L, lua_TValue * func, int nresults) Zeile 320 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaV_execute(lua_State * L, int nexeccalls) Zeile 591 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_call(lua_State * L, lua_TValue * func, int nResults) Zeile 378 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!lua_call(lua_State * L, int nargs, int nresults) Zeile 782 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!ll_require(lua_State * L) Zeile 484 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_precall(lua_State * L, lua_TValue * func, int nresults) Zeile 320 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaV_execute(lua_State * L, int nexeccalls) Zeile 591 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_call(lua_State * L, lua_TValue * func, int nResults) Zeile 378 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!f_call(lua_State * L, void * ud) Zeile 800 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_rawrunprotected(lua_State * L, void (lua_State *, void *) * f, void * ud) Zeile 116 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!luaD_pcall(lua_State * L, void (lua_State *, void *) * func, void * u, int old_top, int ef) Zeile 464 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!lua_pcall(lua_State * L, int nargs, int nresults, int errfunc) Zeile 821 C
  fs2_open_3_7_3_SSE2-DEBUG.exe!script_state::RunBytecodeSub(int in_lang, int in_idx, char format, void * data) Zeile 879 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!script_state::RunBytecode(script_hook & hd, char format, void * data) Zeile 921 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!ConditionedHook::Run(script_state * sys, int action, char format, void * data) Zeile 523 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!script_state::RunCondition(int action, char format, void * data, object * objp, int more_data) Zeile 932 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!game_enter_state(int old_state, int new_state) Zeile 6507 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!gameseq_set_state(int new_state, int override) Zeile 284 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!game_process_event(int current_state, int event) Zeile 5530 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!gameseq_process_events() Zeile 399 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!game_main(char * cmdline) Zeile 7175 C++
  fs2_open_3_7_3_SSE2-DEBUG.exe!WinMain(HINSTANCE__ * hInst, HINSTANCE__ * hPrev, char * szCmdLine, int nCmdShow) Zeile 7244 C++
  [Externer Code]
Title: Re: 3.7.2 + lua socket crashes
Post by: m!m on October 26, 2015, 05:23:19 am
Yeah, as I expected it crashes within the code of the other lua VM. I think this problem is caused by the lua DLL because it basically creates a second lua VM that is different from the VM FSO uses. There is not much the SCP can do to fix that (I'm still not sure why it worked before but that may just have been a coincidence).
You could try using a Proxy DLL (http://lua-users.org/wiki/LuaProxyDllFour) that redirects the lua function calls to the lua VM used by FSO.