View Issue Details

IDProjectCategoryView StatusLast Update
0001402NoesisGUIC# SDKpublic2020-04-21 16:55
Reporterai_enabled Assigned Tosfernandez  
PrioritynormalSeverityminor 
Status resolvedResolutionno change required 
Product Version2.2.0b5 
Target Version3.0.0Fixed in Version3.0.0 
Summary0001402: RangeBase.ValueChanged new value broken
Description

Hi guys,

I've noticed that for a Slider control RoutedPropertyChangedEventArgs<double>.NewValue always contains the same value which is incorrect. As a workaround, I'm using Slider.Value directly inside my ValueChanged event handler.

Regards!

PlatformAny

Relationships

has duplicate 0001656 closedsfernandez Incorrect args for Slider.ValueChanged event 

Activities

sfernandez

sfernandez

2019-01-30 13:44

manager   ~0005425

This is happening because your changes from float to double are only on the C# side. Native code still stores everything in float, and in that particular case, as you are asking for a RoutedPropertyChangedEventArgs<double> and the data stored in memory are 2 floats, the raw conversion is accessing unknown memory.

You can hack your code in NoesisEvents.cs by forcing the use of float args in case T is double. It should work as RangeBase.ValueChanged is the only control using these float args:

public T OldValue
{
get
{
return typeof(T) == typeof(double) ?
(T)(object)(double)RoutedPropertyChangedEventArgsHelper.GetOldValue<float>(getCPtr(this)) :
RoutedPropertyChangedEventArgsHelper.GetOldValue<T>(getCPtr(this));
}
}

public T NewValue
{
get
{
return typeof(T) == typeof(double) ?
(T)(object)(double)RoutedPropertyChangedEventArgsHelper.GetNewValue<float>(getCPtr(this)) :
RoutedPropertyChangedEventArgsHelper.GetNewValue<T>(getCPtr(this));
}
}

Anyway, I will try to find a way to make this more robust in the native side.

ai_enabled

ai_enabled

2019-01-30 14:18

updater   ~0005427

Thank you for a quick reply, Sergio!

I'm reporting this as a bug as it was working fine before. So something has been changed.

Regarding the possible solution - I see it's possible to modify Extend.GetNativePropertyType so that it will return NativePropertyType.Float for double and decimal (and NativePropertyType.NullableFloat for the nullable counterparts).

Then you can rewrite GetOld/New value to use something like that:


int type = Extend.GetNativePropertyType(typeof(T));
IntPtr value = Noesis_RoutedPropertyChangedEventArgs_GetNewValue(cPtr, type); // or get old value
Error.Check();

var result = Extend.GetProxy(value, true);
return result is T || ReferenceEquals(result, null)
? (T)result
: Extend.ConvertValue<T>(result);

Seems to work fine here!

ai_enabled

ai_enabled

2019-01-30 14:21

updater   ~0005428

Last edited: 2019-01-30 14:23

With C# 7.1 you can use it like this for better performance:


int type = Extend.GetNativePropertyType(typeof(T));
IntPtr value = Noesis_RoutedPropertyChangedEventArgs_GetNewValue(cPtr, type); // or get old value
Error.Check();

var result = Extend.GetProxy(value, true);
if (result is T castedResult)
{
return castedResult;
}

if (ReferenceEquals(result, null))
{
return default;
}

return Extend.ConvertValue<T>(result);

ai_enabled

ai_enabled

2020-04-15 17:28

updater   ~0006213

Hi Sergio,
as you've replied in another ticket:
"changing Extend.GetNativePropertyType to return Float for double/decimal types."
— I've done this and it indeed fixes the issue.
Will you use it as a primary solution to this issue or it might have some side effects?

sfernandez

sfernandez

2020-04-16 10:12

manager   ~0006215

No, it will have no side effects, it is safe to use it in your case.

Issue History

Date Modified Username Field Change
2019-01-28 09:49 ai_enabled New Issue
2019-01-29 11:34 sfernandez Assigned To => sfernandez
2019-01-29 11:34 sfernandez Status new => assigned
2019-01-30 13:44 sfernandez Status assigned => feedback
2019-01-30 13:44 sfernandez Note Added: 0005425
2019-01-30 14:18 ai_enabled Note Added: 0005427
2019-01-30 14:18 ai_enabled Status feedback => assigned
2019-01-30 14:21 ai_enabled Note Added: 0005428
2019-01-30 14:22 ai_enabled Note Edited: 0005428
2019-01-30 14:23 ai_enabled Note Edited: 0005428
2020-04-15 13:12 sfernandez Relationship added has duplicate 0001656
2020-04-15 17:28 ai_enabled Note Added: 0006213
2020-04-16 10:12 sfernandez Status assigned => feedback
2020-04-16 10:12 sfernandez Target Version => 3.0.0
2020-04-16 10:12 sfernandez Note Added: 0006215
2020-04-21 16:55 sfernandez Status feedback => resolved
2020-04-21 16:55 sfernandez Resolution open => no change required
2020-04-21 16:55 sfernandez Fixed in Version => 3.0.0