Comments on: XPLMInstance: Two Tricks https:/2020/04/xplminstance-two-tricks/ Developer resources for the X-Plane flight simulator Wed, 29 Apr 2020 18:43:19 +0000 hourly 1 https://wordpress.org/?v=6.6.1 By: Ben Supnik https:/2020/04/xplminstance-two-tricks/#comment-36706 Wed, 29 Apr 2020 18:43:19 +0000 http://developer.x-plane.com/?p=39857#comment-36706 In reply to Yuri Lyubimkin.

Yuri – right. I think this is a known bug – if your instance list is null you have to pass us SOME non-null ptr. This will be fixed in beta 7, but if you want to run on all eversions, pass a ptr to ad ummy float.

]]>
By: Yuri Lyubimkin https:/2020/04/xplminstance-two-tricks/#comment-36701 Wed, 29 Apr 2020 17:08:07 +0000 http://developer.x-plane.com/?p=39857#comment-36701 In reply to Ben Supnik.

Anyway, during my tests I was able to replicate the crash by taking the code from Instancing Drawing example here in the Sample Code section, changing dataref list argument in XPLMCreateInstance to { NULL } and data pointer in XPLMSetInstancePosition to nullptr.

]]>
By: Ben Supnik https:/2020/04/xplminstance-two-tricks/#comment-36673 Tue, 28 Apr 2020 22:30:41 +0000 http://developer.x-plane.com/?p=39857#comment-36673 In reply to Vít Ženíšek.

This does not make sense. Passing null for the dataref string list should crash 100% of the time on all platforms, regardless of the OBJ.

]]>
By: Vít Ženíšek https:/2020/04/xplminstance-two-tricks/#comment-36670 Tue, 28 Apr 2020 22:12:38 +0000 http://developer.x-plane.com/?p=39857#comment-36670 In reply to Ben Supnik.

This works for animated objects:
mXPLInstance = XPLMCreateInstance(mpDef->XPLObject(), nullptr);
static float dummy = 0;
if (mXPLInstance)
XPLMInstanceSetPosition(mXPLInstance, &mActualInfo, &dummy);

This works too:
static const char * drefs[] = { NULL };
mXPLInstance = XPLMCreateInstance(mpDef->XPLObject(), drefs);
static float dummy = 0;
if (mXPLInstance)
XPLMInstanceSetPosition(mXPLInstance, &mActualInfo, &dummy);

This does not work for animated objects but works for objects without animation:
mXPLInstance = XPLMCreateInstance(mpDef->XPLObject(), nullptr);
if (mXPLInstance)
XPLMInstanceSetPosition(mXPLInstance, &mActualInfo, nullptr);

]]>
By: Ben Supnik https:/2020/04/xplminstance-two-tricks/#comment-36666 Tue, 28 Apr 2020 20:50:39 +0000 http://developer.x-plane.com/?p=39857#comment-36666 In reply to Vít Ženíšek.

Let me see if I understand: you are saying that if you pass:
const char * drefs[] = { NULL };
as your dref list, then you crash if you set the instance data to NULL, but NOT if you set the instance data to a dummy ptr?
(This wouldn’t surprise me and is not great by us – I think we are exposing the undefined behavior of memcpy.)

Passing NULL as the dataref list is not allowed – we need a null terminated list.

]]>
By: Ben Supnik https:/2020/04/xplminstance-two-tricks/#comment-36665 Tue, 28 Apr 2020 20:48:57 +0000 http://developer.x-plane.com/?p=39857#comment-36665 In reply to Fergus.

No, ATTR_hard will not work with instancing. ATtributes that require being DSF attached and ACF attached won’t work – this means solid wall, cockpit texture, hard and draped among others.

]]>
By: Vít Ženíšek https:/2020/04/xplminstance-two-tricks/#comment-36662 Tue, 28 Apr 2020 19:53:36 +0000 http://developer.x-plane.com/?p=39857#comment-36662 In reply to Ben Supnik.

You are right Ben, it works. Thank you for correction. I still have to provide a dummy float as data for XPLMInstanceSetPosition to avoid the crash.
To my excuse, the “const char * drefs[] = { “”, NULL };” idea came to me at 2:30 AM while trying to solve my problem with animated model usage.

I originally provided nullptr as input for both functions as I tried to indicate I am not interested in driving any datarefs myself. It worked well for objects without animations, but as soon as there was at least 1 animation in the model, I got a crash.

Anyway, thank you, I am happy now and so will be our virtual airline simulating HEMS in X-Plane!

Vita

]]>
By: Fergus https:/2020/04/xplminstance-two-tricks/#comment-36661 Tue, 28 Apr 2020 19:08:31 +0000 http://developer.x-plane.com/?p=39857#comment-36661 In relation to Instanced objects should the ATTR_hard work when set in the object? I’ve found it doesn’t and I’m not sure if it’s a bug or if it’s intended.

]]>
By: Yuri Lyubimkin https:/2020/04/xplminstance-two-tricks/#comment-36659 Tue, 28 Apr 2020 18:19:34 +0000 http://developer.x-plane.com/?p=39857#comment-36659 In reply to Ben Supnik.

Btw, this is the exact issue I’ve mentioned earlier in the topic. There’s no way to use zero-length list of datarefs and pass nullptr as datarefs values for instance position without a crash, if the instanced object actually has any dataref attached.

Using at least one dataref to control the object instance – is a workaround we’re currently doing for such objects.

]]>
By: Ben Supnik https:/2020/04/xplminstance-two-tricks/#comment-36657 Tue, 28 Apr 2020 16:50:36 +0000 http://developer.x-plane.com/?p=39857#comment-36657 In reply to Nico87.

You can’t add manipulators to instanced objects. Only the cockpit object can have manipulators.

]]>