Jump to content
The simFlight Network Forums

FSX Crashes ... event.cancel


Recommended Posts

Hi

 

I just wrote a small piece of code test.lua fired by a button press and when the aircraft gear is activated I wanted to display gear up or gear down as a message.
 

I dont know if I'm implementing event,cancel properly.Below is the code snippet that is causing the crash.

 

Thank you

 
 
test.lua
function geardown(offs, val)
msg = ""
if val == 0 then 
   msg = " up "
 else
   msg = " down "
end
ipc.display ( "gear"..msg)
 
-- cancel the event so that next time button press should not do action.
event.cancel("geardown") [ this causes the crash..if i comment out this line then no problem]
end
-- to kick it all off:
event.offset(0x0BE8, "UW", "geardown")
 
following is the error line from the console window
 
    38438 LUA.0: Waiting for an event in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    38438 LUA.0: Offset Change event: calling "geardown" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    38438 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:5
    38438 LUA.0: Local: offs = 3048
    38454 LUA.0: Local: val = 16383
    38470 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:6
    38470 LUA.0: Global: msg = 
    38485 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:9
    38501 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:11
    38501 LUA.0: Global: msg =  down 
    38532 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:12
    38548 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:13
    38641 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:14
    38641 LUA.0: VRI read event: calling "" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    38641 *** LUA Error: attempt to call a nil value
    38641 LUA.0: (null) event: calling "!" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    38641 *** LUA Error: attempt to call a nil value
    38641 LUA.0: (null) event: calling "\" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    38641 *** LUA Error: attempt to call a nil value
    38641 LUA.0: U‹ìV‹uhxêÉg‹Æè¼þÿPèéÅþÿYY^]ÃU‹ì‹EWhxêÉgèþ»þÿ¸4  event: calling "lua:10" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    38641 *** LUA Error: attempt to call a nil value
    38641 LUA.0: gvars = {}
 

 

test.lua.txt

Link to comment
Share on other sites

I just wrote a small piece of code test.lua fired by a button press and when the aircraft gear is activated I wanted to display gear up or gear down as a message.

 

I dont know if I'm implementing event,cancel properly.Below is the code snippet that is causing the crash.

 

How are you starting this Lua plug-in? Just by button press? If so you should not use the event system at all. That's for keeping plug-ins running looking for events. You program is more suited to loading once at the start of FS (eg via ipcReady, or using an [Auto] section in the INI file). That way you wouldn't cancel the event in any case.

 

Does the same button press also operate the gear? If so, there's a timing element too.

 

Are you using the current version of FSUIPC, 4.945a? If not please try again with that -- not that it will change things, it is jst that the error data I need will then releate to the current state.

 

Can you then please provide the crash details from Windows? I need the error code, module name and offset. If you can't get it displayed on screen, check the Windows event viewer.

 

I've got to go out for a couple of hours or so. I'll check further when I return, trying things here as well -- once I know how you are starting it, because it doesn't appear to make proper sense as a one-shot.

 

Pete

Link to comment
Share on other sites

just to add to the above...

 

function geardown(offs, val)
msg = ""
if val == 0 then 
   msg = " up "
 else
   msg = " down "
end
ipc.display ( "gear"..msg)
 
-- cancel the event so that next time button press should not do action.
event.cancel("geardown") [ this causes the crash..if i comment out this line then no problem]
*************** if i add the following line of code the crash goes away
ipc.exit()
 
 
end
Link to comment
Share on other sites

Your second message crossed with my first reply.

 

in addition to what I asked there, could you make sure logging is going to the FSUIPC4.LOG file (not the separate Lua file option), and enable

 

-- button logging

-- event logging

-- monitor 0BE8 (on the right hand side) as type U16.

 

That way  I can see the relative timing of the things happening in relation to the Lua execution.

 

This is with your original code, for now (which i still think is, er, rather odd ... ;-) ).

 

Back about 5pm UK ...

 

Pete

Link to comment
Share on other sites

The lua plug in will finally go into ipcReady once it takes shape, but for now in the learning phase,,,just trying a few things

 

Here are the details..

    48017 Starting everything now ...
    48017 LUA.0: beginning "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\ipcReady.lua"
    48017 LUA.0: ...es\Microsoft Flight Simulator X\Modules\ipcReady.lua:1
    48017 LUA.0: Global: ipcPARAM = 0
    48033 LUA.0: ended "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\ipcReady.lua"
    48048 FollowMe service initialised and ready ...
    49343 Advanced Weather Interface Enabled
    52697 KEYDOWN: VK=76, Waiting=0, Repeat=N, Shifts=0
    52697 .. Key not programmed -- passed on to FS
    52697 *** EVENT: Cntrl= 65574 (0x00010026), Param= 0 (0x00000000) ALL_LIGHTS_TOGGLE
    52978 KEYUP: VK=76, Waiting=0
    63383 Button changed: bRef=0, Joy=0, Btn=1, Pressed
    63383 [buttons] 15=P0,1,CL7:R,0
    63383 LUA.0: beginning "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    63383 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:17
    63399 LUA.0: Global: ipcPARAM = 0
    63399 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:4
    63414 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:22
    63430 LUA.0: Waiting for an event in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    63430 LUA.0: Offset Change event: calling "geardown" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    63430 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:5
    63445 LUA.0: Local: offs = 3048
    63461 LUA.0: Local: val = 16383
    63461 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:6
    63477 LUA.0: Global: msg = 
    63477 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:9
    63492 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:11
    63508 LUA.0: Global: msg =  down 
    63539 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:12
    63586 Button changed: bRef=0, Joy=0, Btn=1, Released
    64054 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:13
    64069 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:17
    64085 LUA.0: Waiting for an event in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    93803 Button changed: bRef=0, Joy=0, Btn=1, Pressed
    93803 [buttons] 15=P0,1,CL7:R,0
    93834 LUA.0: ended "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    93850 LUA: "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua": killed
    93866 LUA.0: beginning "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    93866 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:17
    93881 LUA.0: Global: ipcPARAM = 0
    93881 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:4
    93897 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:22
    93912 LUA.0: Waiting for an event in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    93912 LUA.0: Offset Change event: calling "geardown" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    93912 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:5
    93928 LUA.0: Local: offs = 3048
    93944 LUA.0: Local: val = 16383
    93944 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:6
    93959 LUA.0: Global: msg = 
    93959 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:9
    93975 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:11
    93990 LUA.0: Global: msg =  down 
    94022 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:12
    94053 Button changed: bRef=0, Joy=0, Btn=1, Released
    94536 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:13
    94536 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:17
    94536 LUA.0: Waiting for an event in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    99856 KEYDOWN: VK=71, Waiting=0, Repeat=N, Shifts=0
    99856 .. Key not programmed -- passed on to FS
    99856 *** EVENT: Cntrl= 65570 (0x00010022), Param= 0 (0x00000000) GEAR_TOGGLE
    99872 Monitor IPC:0BE8 (U16) = 0
    99872 SimRead: 0BE8="GEAR HANDLE POSITION"
            FLT64: 0
    99887 LUA.0: Offset Change event: calling "geardown" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
    99887 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:5
    99903 LUA.0: Local: val = 0
    99903 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:6
    99918 LUA.0: Global: msg = 
    99934 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:7
    99934 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:11
    99950 LUA.0: Global: msg =  up 
    99950 KEYUP: VK=71, Waiting=0
    99965 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:12
   100496 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:13
   100496 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:14
   100511 LUA.0: ... Games\Microsoft Flight Simulator X\Modules\test.lua:17
   100511 LUA.0: Write Intercept event: calling "" in "D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\test.lua"
   100527 *** LUA Error: attempt to call a nil value
 
windows event viewer
Faulting application name: fsx.exe, version: 10.0.61472.0, time stamp: 0x475e17d3
Faulting module name: FSUIPC4.dll, version: 4.9.4.2, time stamp: 0x55bff8ac
Exception code: 0xc0000005
Fault offset: 0x0008f705
Faulting process id: 0x45c
Faulting application start time: 0x01d0f6ca57e6290f
Faulting application path: D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\fsx.exe
Faulting module path: D:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\Modules\FSUIPC4.dll
Report Id: d6c00039-62bd-11e5-add1-bd28d58471e6
Link to comment
Share on other sites

test.lua

-----------

 
 
 
function geardown(offs, val)
msg = ""
if val == 0 then 
   msg = " up "
 else
   msg = " down "
end
ipc.display ( "gear"..msg)
ipc.sleep(500)
if msg == " up " then
event.cancel("geardown")
-- ipc.exit()
end
end
 
 
 
-- to kick it all off:
event.offset(0x0BE8, "UW", "geardown")
Link to comment
Share on other sites

Well, the Windows crash data wasn't of use because you forgot to update to the current FSUIPC version as I asked -- you are still using 4.942!

 

But there is an error somewher in the ewvent processing in the Lua package. I won't have time to work it out until after I return from holiday, on October 5th. But the  reason seems somrthing to do with the fact that the event has already been triggered when you cancel it. The cancellation removes the function from the list of callable functions, and the pending event gets rubbish.

 

I don't know why, but I will find out.

 

The reason the "ipc.exit" stopped it is simply that this kills the plug-in completely, whereas just ending the function allows the next pending event to be processed.

 

However, this sort of thing would not occur in normal practice. The plug-in is being initiated by a button press. This will immediately, without any change in the offset 0BE8, action the function with the current value of the offset -- the event function is designed to do this, to always call the function initially, with the current value. So the same effect could be achieved without using events at all. Just:

 

msg = ""
val = ipc.readUW(0x0BE8)
if val == 0 then 
   msg = " up "
 else
   msg = " down "
end
ipc.display ( "gear"..msg)

would be more appropriate. I'm not sure why you'd want the thing started by a key press and ended immediately (by the event.cancel -- cancelling the only event would / should terminate the plug-in (and this will probably be part of the 'fix')).

 

I don't understand the relevance of your last post, with a revised version of your test.lua..

 

BTW the offset you are using doesn't give you the state of the Gear, only the state of the gear handle. You know that, don't you?

 

Pete

 

Link to comment
Share on other sites

Thanks Mr.Pete

 

Happy Holidays!

 

I dont want to use trigger it off from a button. More so it will be called from ipcReady ( basically to do after take off procedures ) ..button was just for testing purpose.

 

There was some change in the code as i was testing and hence i posted back the new code - never mind that.

 

As I understand,  the listner ( events ) keep adding to the windows queue for processing but at a certain point ( when user conditions were met) the function was cancelled (function pointer became null ) so when the pending events ( windows queue) fired they were trying to execute a function pointer pointing to null causing the crash.

Link to comment
Share on other sites

As I understand,  the listner ( events ) keep adding to the windows queue for processing but at a certain point ( when user conditions were met) the function was cancelled (function pointer became null ) so when the pending events ( windows queue) fired they were trying to execute a function pointer pointing to null causing the crash.

 

Something like that. not sure why yet. I'll find out when I get back.

 

Meanwhile, if you are starting it from ipcReady or an [Auto] section, you don't need or want any "event.cancel". If you were just using a key assignment to test it, I'm not sure why you used cancel anyway. Why was that? If you try to run the same plug-in again, eg, via a keypress or button, the former incarnation is killed ruthlessly in any case. Or you could assign another key to "Luakill test" which does the same thing..

 

Anyway, I'll look at fixing the real problem, no ,atter how iIllogical it might be, when I get back. So thanks for reporting it.

 

Pete

Link to comment
Share on other sites

Assuming you are having a continually running gear handle monitor, this would suit. Load it in ipcReady, or via [Auto], or once by key or button assignment:

 

function geardown(off, val)
 if val == 0 then 
   msg = " up "
 else
   msg = " down "
end
ipc.display ( "gear"..msg, 5)
end
event.offset(0x0BE8, "UW", "geardown")

The display lasts 5 seconds. if you want a permanent display, remove the ", 5" in the display call.

Pete
 
Link to comment
Share on other sites

  • 2 weeks later...

I managed to reproduce the problem with event.cancel. It was an interlocking difficulty -- the cancel was removing an element in a chain whilst the loop processing the chain was still operating, and though it was interlocked correctly in most places, there was one gap in the locking. The timing of your plug-in style was just right to fall into this gap!

 

For future reference, I've fixed it in  the latest version, 4.946b, though the fix won't be listed in the "Changes" document till 4.947.

 

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.