SDK Question Bug found in GetExhaustSpec

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
Hi guys,

I think I found a bug in the function GetExhaustSpec(UINT idx, EXHAUSTSPEC* spec) and it seems to me that is present also in the other version of GetExhaustSpec.

Apparently the idx the function is reading is the exhaust counter and not the ID of the exhaust: when I delete an exhaust that is not the last of the list and I use the function with the latest ID orbiter crashes and from the debug it comes out that it crashes because the spec is rubbish.
I made a check printing out all the exhaust ID in the sim and I am calling the right ID, but if I delete an intermediate exhaust the function does not work anymore.
The only way I found to make it work is the following:
Code:
UINT ID =  the ID I want to check
EXHAUSTSPEC es;
for (DWORD i = 0; i < VB1->GetExhaustCount(); i++) {
		VB1->GetExhaustSpec(i, &es);
		if (es.id == ID) {
			break;
		}
	}

I hope I made myself clear enough.

Tested only in Orbiter2016, not in beta.

Fred
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,217
Reaction score
1,563
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
Per the docs for GetExhaustSpec:
Code:
* \param [in] idx exhaust identifier

That parameter is `UINT idx` (an unsigned integer, not a HANDLE), and "idx" means "index". To me, it reads as if it's working as designed: that it's an index between 0 and (GetExhaustCount()-1), and so if you delete an intermediate exhaust then all the exhaust indexes above its position in the list will shift. Therefore, you can't assume the same exhaust index will always remain valid across multiple frames if you delete any exhausts. Also, if the behavior of this method were to change, it would break every add-on out there that currently uses it. :)

If you need to maintain a reference to a given exhaust spec, you can just store the EXHAUSTSPEC * you initially pass to AddExhaust rather than trying to re-retrieve that spec pointer later by calling GetExhaustSpec. In other words, you shouldn't need to use GetExhaustSpec to keep track of or modify your own exhaust specs that your own vessel code creates -- GetExhaustSpec() is only necessary if you need to enumerate and read other vessels' exhaust specs. Does that all make sense?
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,667
Reaction score
104
Points
78
I understand what you mean but TBH I do not agree, and I think that there are clues that I am right about this:

1) the AddExhaust function returns the UINT which the docs call "Exhaust identifier" and to me an identifier is used to identify uniquely.
2) the id reserved parameter of Exhaustspec remains the same, as a matter of fact my workaround of the issue works. So they actually do not shift. I am sure about this because I checked with a series of exhausts added and deleted and the id always remained the same.
3) If what you say is true, the function GetExhaustSpec doesn't make much sense, since it could basically only be used in a loop cycle through all the specs.

The fact that the identifier is a UINT and not a Handle doesn't change much, a handle is just an alias for any kind of implementaiton behind an identifier, in this case the implementation is shown and not hidden.

It seems pretty clear to me that the original intention was to return through the addexhaust the identifier that is stored in the exhaustspec id reserved parameter and let the users recall the spec using the id, so I pretty much think it's a bug. And I also think that there are not many addons that use this particular function, since usually the exhaust are just added and get deleted with the relevant engine, so it is quite rare to query the sim for their parameters, I think that is why this thing never came out before.

I could be wrong of course, only martins can tell us the true story ;)

---------- Post added at 21:10 ---------- Previous post was at 18:00 ----------

In addition, to what above said the DelExhaust function accepts just the UINT idx as a parameter, so even though I could retrieve the specs from what I created, I surely need to be able to delete a specific exhaust, and the only identifier is the ID, so to me this is a further confirmation that even though it is not a show stopper, the GetExhaustSpec has a bug
 
Top