MultiDensityImageSource as global

#1

Hello, Im trying to add a MultiDensityImageSource as a global to be able to reuse it but I’m getting an error.

Fuse version 0.26.0 (build 7741)

<App>
    <MultiDensityImageSource ux:Global="GlobalKey">
        <FileImageSource Density="1" File="image.png"/>
        <FileImageSource Density="2" File="image.png"/>
        <FileImageSource Density="3" File="image.png"/>
    </MultiDensityImageSource>

    <Image Source="GlobalKey"/>
</App>

Configuring (3.7s)

Compiling syntax tree (1.9s)

Generating code and data (3.7s)

Build completed in 9.29 seconds

# Build complete.

Output: GL_VERSION: 2.1 INTEL-10.14.73
Output: GL_VENDOR: Intel Inc.
Output: GL_RENDERER: Intel(R) Iris(TM) Graphics 6100
Output: System.ArgumentException: An item with the same key has already been added.
  at System.ThrowHelper.ThrowArgumentException (ExceptionResource resource) <0x145f71b8 + 0x0002f> in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) <0x665930 + 0x0015b> in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) <0x44a8a48 + 0x00027> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.Environment.Bind (Outracks.Simulator.Bytecode.Variable variable, System.Object value) <0x145f3928 + 0x00023> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x11ff71b8 + 0x00117> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.LambdaClosure.Func (System.Object a1) <0x145f6368 + 0x00064> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.LambdaClosure.Action (System.Object a1) <0x145f6338 + 0x0001b> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (System.Object lambda, System.Object[] arguments) <0x145f5d78 + 0x002e5> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Evaluate (Outracks.Simulator.Bytecode.CallLambda i) <0x145f45b8 + 0x0004f> in <filename unknown>:0 
  at Outracks.Simulator.Bytecode.Expression.Match[T] (System.Func`2 a1, System.Func`2 a2, System.Func`2 a3, System.Func`2 a4, System.Func`2 a5, System.Func`2 a6, System.Func`2 a7, System.Func`2 a8, System.Func`2 a9, System.Func`2 a10, System.Func`2 a11, System.Func`2 a12, System.Func`2 a13, System.Func`2 a15, System.Func`2 a16) <0x11ff7c28 + 0x00261> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Evaluate (Outracks.Simulator.Bytecode.Expression expression) <0x11ff7688 + 0x00563> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (IEnumerable`1 statements) <0x11ff7538 + 0x00077> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x11ff71b8 + 0x00157> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.VirtualMachine.Execute (IReflection reflection, Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x11ff6f48 + 0x000af> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.VirtualMachine.Execute (Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x11ff6f10 + 0x00023> in <filename unknown>:0 
  at Outracks.Simulator.Reifying.OnEnterState () <0x11ffa368 + 0x000b7> in <filename unknown>:0 
  at Outracks.Simulator.Application.SetState (Outracks.Simulator.State nextState) <0xf4a1248 + 0x00054> in <filename unknown>:0 
  at Outracks.Simulator.Application.OnUpdate () <0xf4a0da0 + 0x000c7> in <filename unknown>:0 
  at Fuse.App.Update () <0xf4a0c60 + 0x00026> in <filename unknown>:0 
An item with the same key has already been added.
#2

If I use just 1 Image source I have another error:

<App>
    <MultiDensityImageSource ux:Global="GlobalKey">
        <FileImageSource Density="1" File="image.png"/>
    </MultiDensityImageSource>

    <Image Source="GlobalKey"/>
</App>

Configuring (4.1s)

Compiling syntax tree (2.0s)

Generating code and data (3.1s)

Build completed in 9.24 seconds

# Build complete.

Output: GL_VERSION: 2.1 INTEL-10.14.73
Output: GL_VENDOR: Intel Inc.
Output: GL_RENDERER: Intel(R) Iris(TM) Graphics 6100
Output: System.ArgumentNullException: Value cannot be null.
Parameter name: key
  at System.ThrowHelper.ThrowArgumentNullException (ExceptionArgument argument) <0x130f3e68 + 0x0002f> in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (System.Collections.Generic.TKey key) <0x7647d0 + 0x0001b> in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].TryGetValue (System.Collections.Generic.TKey key, System.Collections.Generic.TValue& value) <0x764718 + 0x0001f> in <filename unknown>:0 
  at Uno.UX.Resource.SetGlobalKey (System.Object obj, System.String key) <0x130f1da0 + 0x00173> in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x457ae78 + 0x0008f> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x130f4810 + 0x0002b> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.TryInvokeExtension.Try (System.Func`1 func) [0x0000d] in /usr/local/Teamcity/Agents/tcagent-osx-agent01-teamcity-dyson/work/b939dc4c6ac331f9/Source/Outracks.Simulator.Runtime/Reflection/CompiledTypeReflection.cs:286 
  at Outracks.Simulator.Runtime.TryInvokeExtension.TryInvoke (System.Reflection.MethodInfo mi, System.Object obj, System.Object[] value) [0x0001b] in /usr/local/Teamcity/Agents/tcagent-osx-agent01-teamcity-dyson/work/b939dc4c6ac331f9/Source/Outracks.Simulator.Runtime/Reflection/CompiledTypeReflection.cs:275 
  at Outracks.Simulator.Runtime.CompiledTypeReflection.CallStatic (Outracks.Simulator.Bytecode.TypeName typeName, Outracks.Simulator.Bytecode.TypeMemberName methodName, System.Object[] arguments) [0x00020] in /usr/local/Teamcity/Agents/tcagent-osx-agent01-teamcity-dyson/work/b939dc4c6ac331f9/Source/Outracks.Simulator.Runtime/Reflection/CompiledTypeReflection.cs:127 
  at Outracks.Fuse.Preview.RuntimeObjectPoker.<HookUpReflectionInterface>m__1 (System.String a, System.String b, System.Object[] c) [0x00000] in /usr/local/Teamcity/Agents/tcagent-osx-agent01-teamcity-dyson/work/b939dc4c6ac331f9/Source/Outracks.Fuse.Preview/RuntimeObjectPoker.cs:28 
  at Outracks.Simulator.Reflection.DelegateReflection.Outracks.Simulator.Runtime.IReflection.CallStatic (Outracks.Simulator.Bytecode.TypeName typeName, Outracks.Simulator.Bytecode.TypeMemberName methodName, System.Object[] arguments) <0x128f8ad0 + 0x0003e> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Evaluate (Outracks.Simulator.Bytecode.CallStaticMethod m) <0x128f81b8 + 0x00059> in <filename unknown>:0 
  at Outracks.Simulator.Bytecode.Expression.Match[T] (System.Func`2 a1, System.Func`2 a2, System.Func`2 a3, System.Func`2 a4, System.Func`2 a5, System.Func`2 a6, System.Func`2 a7, System.Func`2 a8, System.Func`2 a9, System.Func`2 a10, System.Func`2 a11, System.Func`2 a12, System.Func`2 a13, System.Func`2 a15, System.Func`2 a16) <0x128f7d08 + 0x002ac> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Evaluate (Outracks.Simulator.Bytecode.Expression expression) <0x128f7768 + 0x00563> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (IEnumerable`1 statements) <0x128f7618 + 0x00077> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x128f7298 + 0x00157> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.LambdaClosure.Func (System.Object a1) <0x130f15e8 + 0x00064> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.LambdaClosure.Action (System.Object a1) <0x130f15b8 + 0x0001b> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (System.Object lambda, System.Object[] arguments) <0x130f1108 + 0x002e5> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Evaluate (Outracks.Simulator.Bytecode.CallLambda i) <0x130f02d8 + 0x0004f> in <filename unknown>:0 
  at Outracks.Simulator.Bytecode.Expression.Match[T] (System.Func`2 a1, System.Func`2 a2, System.Func`2 a3, System.Func`2 a4, System.Func`2 a5, System.Func`2 a6, System.Func`2 a7, System.Func`2 a8, System.Func`2 a9, System.Func`2 a10, System.Func`2 a11, System.Func`2 a12, System.Func`2 a13, System.Func`2 a15, System.Func`2 a16) <0x128f7d08 + 0x00261> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Evaluate (Outracks.Simulator.Bytecode.Expression expression) <0x128f7768 + 0x00563> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (IEnumerable`1 statements) <0x128f7618 + 0x00077> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.ScopeClosure.Execute (Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x128f7298 + 0x00157> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.VirtualMachine.Execute (IReflection reflection, Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x128f7028 + 0x000af> in <filename unknown>:0 
  at Outracks.Simulator.Runtime.VirtualMachine.Execute (Outracks.Simulator.Bytecode.Lambda lambda, System.Object[] arguments) <0x128f6ff0 + 0x00023> in <filename unknown>:0 
  at Outracks.Simulator.Reifying.OnEnterState () <0x128fa448 + 0x000b7> in <filename unknown>:0 
  at Outracks.Simulator.Application.SetState (Outracks.Simulator.State nextState) <0xee42b80 + 0x00054> in <filename unknown>:0 
  at Outracks.Simulator.Application.OnUpdate () <0xee426d8 + 0x000c7> in <filename unknown>:0 
  at Fuse.App.Update () <0xee42598 + 0x00026> in <filename unknown>:0 
Value cannot be null.
Parameter name: key
#3

Can anybody help with this?

#4

Sorry for the slow reply. This is clearly a bug, and I’ve created an internal ticket to address this. We’ll let you know when this has been fixed.

#5

Hi,

has it been solved? I’m unable to set MultiDensityImageSource as global resource

#6

No, this issue has not yet been fixed.

#7

Hello, I was wondering if is there any news or workaround about this bug
thanx

#8

Yeah, typically icons are used multiple times in an app, for that, use an icon font.

If its a logo thats used on every page, then define the image once outside of the page/navigation control (like a header on a website) in your <App>. If you still need to hide it at times, then keep a global Observable to do that, and use a <WhileTrue> that uses the Observable.

#9

Hello and thank your for your reply.

I needed to load a different MultiDensity image based on the devise, unfortunately Iphone X, XS, XR and XS Max don’t load correctly a launch image because of the bottom and top white area.

I did this:

<Page>
	<JavaScript>
		var Observable = require("FuseJS/Observable");

		imgLoaded= Observable(true);

		function LoadImg(){
			imgLoaded.value = false;
		}
		module.exports = {LoadImg: LoadImg, imgLoaded: imgLoaded};
	</JavaScript>


	<WhileWindowSize LessThan="376,812" GreaterThan="374,811" Bypass="Never">
		<Callback Handler="{LoadImg}" />
	</WhileWindowSize>	
	<WhileWindowSize LessThan="415,897" GreaterThan="412,895" Bypass="Never">
		<Callback Handler="{LoadImg}" />
	</WhileWindowSize>

	<WhileTrue Value="{imgLoaded}">
		<Rectangle Height="100%" Width="100%" Color="BackgroundColor">
			<Launch StretchMode="UniformToFill" />
		</Rectangle>
	</WhileTrue>
	<WhileFalse Value="{imgLoaded}">
		<Rectangle Height="100%" Width="100%" Color="BackgroundColor">
			<LaunchX StretchMode="UniformToFill" />
		</Rectangle>
	</WhileFalse>
</Page>

Im not sure is the more elegant solution :slight_smile:

#10

Ok, you may want to use the iOS tag too.

#11

Oh wait a sec, you just want to set a launch image for iOS, you can do that with the iOS LaunchImages .unoproj setting: https://fuseopen.com/docs/basics/uno-projects.html#ios-launchimages