methusalah / SplineMesh

A Unity plugin to create curved content in real-time with bézier curves
https://twitter.com/dumas181
MIT License
1.05k stars 104 forks source link

Fix samples initialisation #31

Closed spacecheese closed 4 years ago

spacecheese commented 4 years ago

samples is not initialised correctly when CubicBezierCurve is deserialised resulting in null reference exceptions.

spacecheese commented 4 years ago

I meant to implement MeshBender MinimumStretch mode in a separate PR. This is another mode similar to Repeat that stretches the mesh to avoid leaving a gap at the end of intervals. I'll revert it if you'd like a separate PR or you're not happy with the changes.

methusalah commented 4 years ago

could you explain the scenario in which you need curve sample to be deserialized? It's not abvious in the code, but they aren't meant to be serialized in the first place

spacecheese commented 4 years ago

Sorry my comments weren't very clear. I was having some issues with "GetSampleAtDistance" throwing null reference exceptions after loading the editor because "samples" was null. I think this is because when "CubicBezierCurve" is deserialised "samples" defaults to null. Assigning an empty list to "samples" OnDeserialized seemed to fix this for me.

methusalah commented 4 years ago

I can't understand why you are facing this situation. CubicBezierCurve are set Serializable but I don't remember why. It may not be necessary anymore. CubicBezierCurve and samples are mathematical data that is intended to be built and rebuilt each time the spline component is enabled.

Having samples to null would mean that the spline component "OnEnable" method is never called. So it seems odd to try and get a sample on a disabled spline. Is it your case? And if so, is this something that you are doing intentionnaly?

If an acceptable scenario exists for that, then I will have to think about it before choosing a solution, because the mathematical data has always be intended to be volitile in SplineMesh (not serialized). It may cause regression or may not be logical.

spacecheese commented 4 years ago

Thanks that makes a lot more sense. I must have done something strange to cause this so I'll have more of a look into this.