AM 4.0.2 si_variable_subscribe bug

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Post Reply
Message
Author
User avatar
Sling
Posts: 4594
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

AM 4.0.2 si_variable_subscribe bug

#1 Post by Sling » Sat Jul 03, 2021 10:30 am

As the Subject suggested this is to report an issue with si_variable_subscribe() in the latest AM4 release version. When subscribing to an array type the correct values are not received. This code prints "Array contains 3 items. Data on first position is: 0.0".

Additionally the subscribe callback is called continuously even when data is not changing.

Code: Select all

var1 =si_variable_create("my_variable", "FLOAT[3]", {0.2, 0.3, 0.4})

function new_data_callback(data1)
   -- #data1 would give the array length
   -- data[1] would give the first object in the array
   print("Array contains " .. #data1.. " items. Data on first position is: " .. data1[1])
 end

-- subscribe to the variable
si_variable_subscribe("my_variable", "FLOAT[3]", new_data_callback)

alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Re: AM 4.0.2 si_variable_subscribe bug

#2 Post by alkargr » Fri Jul 23, 2021 10:03 am

Hello,
As Sling said there are some bugs regarding si variables.

I found the following problems:

1. When you use si_variable_create and you initialize the variable with a value, that value isn't returned from the xplane plugin. So when you subscribe to this variable you always get 0.

Code: Select all

var_id = si_variable_create("testVar", "FLOAT", 1.2)
function callback_function(myvar)
    print(myvar)
end
si_variable_subscribe("testVar", "FLOAT", callback_function)
Returns:0

If you write to this variable using the si_variable_write then the plugin returns the values.

Code: Select all

var_id = si_variable_create("testVar", "FLOAT", 1.2)
[b]si_variable_write(var_id, 2.2) [/b]
function callback_function(myvar)
    print(myvar)
end
si_variable_subscribe("testVar", "FLOAT", callback_function)
Returns: 2.2000000476837

2. The request_callback doesn't work on si_variables subscriptions.

Some analysis to help you with debugging:
si_variable_create sends the following JSON:

Code: Select all

write_df:{
	"key":	"testVarFLOAT",
	"size":	1,
	"type":	"FLOAT",
	"type_size":	1,
	"offset":	0,
	"force":	false,
	"value":	"1.200000",
	"unit":	"FLOAT"     --- THIS IS THE DIFFERENCE
}
The plugin answers with 0

si_variable_write sends the following JSON:

Code: Select all

write_df:{
	"key":	"testVarFLOAT",
	"size":	1,
	"type":	"FLOAT",
	"type_size":	1,
	"offset":	0,
	"force":	false,
	"value":	"2.200000"
}
The plugin answers with a value.

However, the value contains wrong floating points (2.2000000476837), and then you always have to use string.format to deal with them.
I guess that is because when you are programming in Java and you deal with decimal numbers and it is advisable to use BigDecimal instead of Double when you need to present numbers with precision.
Consider the following example:

Code: Select all

System.out.println("Subtract Double-Double 1-1.1 = " + (1.0 - 1.1) );
BigDecimal aa = BigDecimal.valueOf(1);
BigDecimal bb = BigDecimal.valueOf(1.1);
aa = aa.subtract(bb);
System.out.println("Subtract BigDecimal-BigDecimal 1-1.1 = " + aa);

Output:
Subtract Double-Double 1-1.1 = -0.10000000000000009
Subtract BigDecimal-BigDecimal 1-1.1 = -0.1
Please use BigDecimal or something equivalent for C++ (i have no idea) if it needs to be changed in the plugin.

And lastly, AM sends continuously the write_df JSON for the same si_variable with the same values, that creates useless network traffic.

Hope that helps, cheers :)

User avatar
Corjan
Posts: 2457
Joined: Thu Nov 19, 2015 9:04 am

Re: AM 4.0.2 si_variable_subscribe bug

#3 Post by Corjan » Sat Jul 24, 2021 7:37 pm

Hi,


Will have a look at the by the end of next week.

The code dealing with the stuff is C(++). Java is just used for the AM GUI.


Corjan

User avatar
Corjan
Posts: 2457
Joined: Thu Nov 19, 2015 9:04 am

Re: AM 4.0.2 si_variable_subscribe bug

#4 Post by Corjan » Fri Aug 06, 2021 10:07 am

Hi,


Found the issue, bug in Air Manager.


Should be solved with next AM BETA,

Corjan

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests