Forums » Bugs
Mission problems when working with the Lua API.
The client crashes when I fiddle with the Lua API for missions. It happens when starting or quitting a mission and I can't find a way to replicate it consistently. I left my code static and it just happens after a while. I've used AbortMission, GetActiveMissionInfo, GetNumActiveMissions and have accessed the _missionlog and MissionLogPanel.log tables. It also just happened when I was started a mission after registering for MISSION_ADDED, MISSION_NOTIFICATION and MISSION_UPDATED.
There are no errors printed to errors.log or openglerr.log. I tail -f'ed both, so I'm not losing information when I restart the client.
However, I ran an strace and I managed to catch a crash:
sched_yield() = 0
select(20, [15 19], [], NULL, {0, 0}) = 1 (in [19], left {0, 0})
recvfrom(19, "\30\5d\346,U\266\314\273c\215\34\202E\360\3426\373\256\0[\371\311\33%,>\274\321+\232\177"..., 2047, 0, {sa_family=AF_INET, sin_port=htons(21141), sin_addr=inet_addr("204.15.102.5")}, [16]) = 74
select(20, [15 19], [19], NULL, {0, 0}) = 2 (in [19], out [19], left {0, 0})
sendto(19, "\1\373d", 3, 0, {sa_family=AF_INET, sin_port=htons(21141), sin_addr=inet_addr("204.15.102.5")}, 16) = 3
recvfrom(19, "\30\5e\347,U\266T\2\270\232#\23C\374\254\350?\227\270\3\254\351\331\320+\373\207K\r\235;"..., 2047, 0, {sa_family=AF_INET, sin_port=htons(21141), sin_addr=inet_addr("204.15.102.5")}, [16]) = 208
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3519, ...}) = 0
write(1, "[Sun Jan 23 23:43:11 2011] You n"..., 83) = 83
write(1, "Fennus R-18 Guardian, Orne Guard"..., 146) = 146
open("INKlingmissions.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 20
fstat(20, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f87d580f000
write(20, "{{id=1170,text={{\"Greetings, pil"..., 32768) = 32768
write(20, "A route has been mapped in your "..., 629) = 629
close(20) = 0
munmap(0x7f87d580f000, 4096) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
close(1) = 0
munmap(0x7f87d59a0000, 4096) = 0
open("errors.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 1
fstat(1, {st_mode=S_IFREG|0644, st_size=4182, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f87d59a0000
fstat(1, {st_mode=S_IFREG|0644, st_size=4182, ...}) = 0
lseek(1, 4182, SEEK_SET) = 4182
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Here's the code that ultimately causes it to crash:
function scratch.go(data, args)
local cnt = GetNumActiveMissions()
print('Found '..cnt..' missios.')
if cnt == 0 then
print('No active missions.')
else
local title = GetActiveMissionInfo(1)
print('First mission of '..cnt..' is: '..title..'.')
local info = _missionlog
local infolen = table.getn(info)
print('Length is '..infolen)
for k, v in ipairs(info) do
print(k..': '..v)
end
print('End info.')
end
end
function scratch.mission(event, data)
print('Event: '..event)
print('Data: '..data)
end
RegisterUserCommand('scratch', scratch.go)
RegisterUserCommand('reload', ReloadInterface)
RegisterEvent(scratch.mission, 'MISSION_ADDED')
RegisterEvent(scratch.mission, 'MISSION_NOTIFICATION')
RegisterEvent(scratch.mission, 'MISSION_UPDATED')
I ran the client without any of that code and started and aborted a bunch of missions and it's stable.
There are no errors printed to errors.log or openglerr.log. I tail -f'ed both, so I'm not losing information when I restart the client.
However, I ran an strace and I managed to catch a crash:
sched_yield() = 0
select(20, [15 19], [], NULL, {0, 0}) = 1 (in [19], left {0, 0})
recvfrom(19, "\30\5d\346,U\266\314\273c\215\34\202E\360\3426\373\256\0[\371\311\33%,>\274\321+\232\177"..., 2047, 0, {sa_family=AF_INET, sin_port=htons(21141), sin_addr=inet_addr("204.15.102.5")}, [16]) = 74
select(20, [15 19], [19], NULL, {0, 0}) = 2 (in [19], out [19], left {0, 0})
sendto(19, "\1\373d", 3, 0, {sa_family=AF_INET, sin_port=htons(21141), sin_addr=inet_addr("204.15.102.5")}, 16) = 3
recvfrom(19, "\30\5e\347,U\266T\2\270\232#\23C\374\254\350?\227\270\3\254\351\331\320+\373\207K\r\235;"..., 2047, 0, {sa_family=AF_INET, sin_port=htons(21141), sin_addr=inet_addr("204.15.102.5")}, [16]) = 208
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3519, ...}) = 0
write(1, "[Sun Jan 23 23:43:11 2011] You n"..., 83) = 83
write(1, "Fennus R-18 Guardian, Orne Guard"..., 146) = 146
open("INKlingmissions.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 20
fstat(20, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f87d580f000
write(20, "{{id=1170,text={{\"Greetings, pil"..., 32768) = 32768
write(20, "A route has been mapped in your "..., 629) = 629
close(20) = 0
munmap(0x7f87d580f000, 4096) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
close(1) = 0
munmap(0x7f87d59a0000, 4096) = 0
open("errors.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 1
fstat(1, {st_mode=S_IFREG|0644, st_size=4182, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f87d59a0000
fstat(1, {st_mode=S_IFREG|0644, st_size=4182, ...}) = 0
lseek(1, 4182, SEEK_SET) = 4182
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Here's the code that ultimately causes it to crash:
function scratch.go(data, args)
local cnt = GetNumActiveMissions()
print('Found '..cnt..' missios.')
if cnt == 0 then
print('No active missions.')
else
local title = GetActiveMissionInfo(1)
print('First mission of '..cnt..' is: '..title..'.')
local info = _missionlog
local infolen = table.getn(info)
print('Length is '..infolen)
for k, v in ipairs(info) do
print(k..': '..v)
end
print('End info.')
end
end
function scratch.mission(event, data)
print('Event: '..event)
print('Data: '..data)
end
RegisterUserCommand('scratch', scratch.go)
RegisterUserCommand('reload', ReloadInterface)
RegisterEvent(scratch.mission, 'MISSION_ADDED')
RegisterEvent(scratch.mission, 'MISSION_NOTIFICATION')
RegisterEvent(scratch.mission, 'MISSION_UPDATED')
I ran the client without any of that code and started and aborted a bunch of missions and it's stable.
If you remove the two registered user commands, do you still have the crash?
If you change the scratch.mission() code and wrap event and data with tostring(), does that fix the problem?
Try removing the prints and see if that helps.
If you change the scratch.mission() code and wrap event and data with tostring(), does that fix the problem?
Try removing the prints and see if that helps.
I followed your steps and after the first one the client crashed but seemed stable after restarting, so I restarted at each level. Now I have all the code enabled with explicit casting in the print statements. It appears to be stable.
Is is a peculiarity with the mission data structures or is it Lua best practices to explicitly cast concatenated variables?
Is is a peculiarity with the mission data structures or is it Lua best practices to explicitly cast concatenated variables?
It's general lua best practices to cast if you are not 100% sure of the data type. For example, you can't concatenate a boolean value (true and false) so you'd have to tostring(blah==1) to get it to print true or false. The same goes for nil. It's just one of those annoying lua things.
I tend to tostring() everything that I am concatenating since tostring() of something that's already a string returns the original string so it doesn't generate a new string. Internally lua creates a string for the object anyways, so there's not much loss to efficiency.
I tend to tostring() everything that I am concatenating since tostring() of something that's already a string returns the original string so it doesn't generate a new string. Internally lua creates a string for the object anyways, so there's not much loss to efficiency.
Thank you, raybondo.