noisypants

Hello,
Does the ContentSerializer handle shared resources at different depth levels

ie:
Obj A references B and C. B and C each reference D. When serializing A, should i see only one instance of D in the <Resources> section

I believe i'm attempting to do this and i'm seeing multiple copies of D in my <Resources> section.

I've made sure the references that i want to be shared are marked with: [ContentSerializer(SharedResource = true)].

Is this something that should work or does this system not handle these situations

thanks
jake


Re: XNA Game Studio Express ContentSerializer and SharedResource

Shawn Hargreaves - MSFT

That will work, as long as the shared resource flag is set for every place that D is referenced.

If you can't figure this out, please post some code that reproduces your problem.





Re: XNA Game Studio Express ContentSerializer and SharedResource

noisypants

I think i figured out my problem.

in the processor for asset A, i use BuildAndLoadAsset to build assets B and C. The processor for each of B and C use BuildAndLoadAsset to get asset D. I had assumed that the calls to BuildAndLoadAsset from B and C with the same parameters would return the same instance of D. This is not the case. So when adding shared resources, B and C each hold a different instance of the data for D and subsequently two copies of D gets written out.

Which brings me to a suggestion. When writing content with ContentWriter.WriteSharedResource, it must be using a comparer that boils down to a call to System.ReferenceEquals. It would be handy if we could specify what IEqualityComparer is used when writing shared resources, so in the above situation, the user could control how the system determined whether an asset has been added or not already.

Thoughts




Re: XNA Game Studio Express ContentSerializer and SharedResource

Shawn Hargreaves - MSFT

That makes sense.

Could you file a suggestion on the connect site about the custom equality comparer idea, please