Jump to content

problem with timer.destroy


Recommended Posts

Hi guys,

 

here's a snippet of the code of my Airbus A310 project. 

 

  if local_dref_getInt(id_a310_elec_pb_idg2_status) == 1 and a310_elec_pb_idg2_timer_started == 0 then --start timer to automatically close the cover after the time is up
    a310_elec_pb_idg2_timer_started = 1
    a310_elec_pb_idg2_timer = timer.newOneShot('a310_function_idg2_timer', 5.0)
    timer.destroy(a310_elec_pb_idg2_timer)
  end
  if local_dref_getInt(id_a310_elec_pb_idg2_status) == 2 and local_dref_getFloat(id_a310_elec_pb_idg2_anim) == 2.0 then --close the cover if the button has been pressed
    a310_elec_pb_idg2_timer_started = 0
  end
 
This code runs without a problem but it makes no sense because the timer is destroyed right after it's being created. So the following code actually makes a lot more sense:
 
  if local_dref_getInt(id_a310_elec_pb_idg2_status) == 1 and a310_elec_pb_idg2_timer_started == 0 then --start timer to automatically close the cover after the time is up
    a310_elec_pb_idg2_timer_started = 1
    a310_elec_pb_idg2_timer = timer.newOneShot('a310_function_idg2_timer', 5.0)
  end
  if local_dref_getInt(id_a310_elec_pb_idg2_status) == 2 and local_dref_getFloat(id_a310_elec_pb_idg2_anim) == 2.0 then --close the cover if the button has been pressed
    a310_elec_pb_idg2_timer_started = 0
    timer.destroy(a310_elec_pb_idg2_timer)
  end
 
The only difference is that I moved the timer.destroy command from the first if-clause to the second one. When I run this code x-plane crashes when the second if-clause is entered. Do you guys have any ideas on what's causing the crash?
 
Kind regards
Martin
Link to post
Share on other sites

Gizmo needs a new timer API call to allow you to query the state of a timer handle.

 

Eg:

if( timer.isAlive( a310_elec_pb_idg2_timer ) )then  timer.destroy( a310_elec_pb_idg2_timer )end

 

I'll be adding this(or something very similar) in the near future.

 

For now you'll have to use ugly guard flag variables to "know things" about timers that the API should be able to tell you directly.

 

 

The crash is caused because the timer has probably expired and been destroyed already as it's a one-shot item.

The fix is to either use a separate additional variable to track the state of the timer or wait for the new API call.

 

 

Thanks for using Gizmo.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...