Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Rewrite tool introduce bugs in local functions #505

Open
tool-buddy opened this issue Feb 26, 2019 · 0 comments
Open

Rewrite tool introduce bugs in local functions #505

tool-buddy opened this issue Feb 26, 2019 · 0 comments

Comments

@tool-buddy
Copy link

tool-buddy commented Feb 26, 2019

In a method that has a local function within it, adding a precondition will lead to the rewrite tool to mess up compile generated class used by the local function.

Here is the IL of the method when compiled with no precondition

private void HandleCrossSection(CrossSection crossSection, bool isLeftSide, AnimationCurve rangeMinCurve, AnimationCurve rangeMaxCurve, bool hasMorphing, string sectionName, Transform parentTransform, CurvyGenerator curvyGenerator, Dictionary<CurvySpline, InputSplineShape> trackSectionCreatedShapeModules, Dictionary<(Material Material, bool IsMagnetized, string sectionName), List<BuildShapeExtrusion>> buildShapeExtrusions, ref Vector3 startOriginTranslation, ref Quaternion startOriginRotation, ref Vector3 endOriginTranslation, ref Quaternion endOriginRotation, InputSplinePath inputSplinePath)
{
	<>c__DisplayClass41_0 <>c__DisplayClass41_ = default(<>c__DisplayClass41_0);
	<>c__DisplayClass41_.trackSectionCreatedShapeModules = trackSectionCreatedShapeModules;
	<>c__DisplayClass41_.<>4__this = this;
	<>c__DisplayClass41_.sectionName = sectionName;
	<>c__DisplayClass41_.parentTransform = parentTransform;
	<>c__DisplayClass41_.crossSection = crossSection;
	<>c__DisplayClass41_.isLeftSide = isLeftSide;
	Debug.LogWarning((object)<>c__DisplayClass41_.crossSection);
	BuildShapeExtrusion buildShapeExtrusion = curvyGenerator.AddModule<BuildShapeExtrusion>();
	buildShapeExtrusion.Resolution = 19;
	buildShapeExtrusion.CrossResolution = 30;
	buildShapeExtrusion.Optimize = false;
	buildShapeExtrusion.CrossOptimize = false;
	buildShapeExtrusion.CrossReverseNormals = false;
	buildShapeExtrusion.Initialize();
	buildShapeExtrusion.set_name("Extrusion_" + <>c__DisplayClass41_.sectionName + "_" + <>c__DisplayClass41_.crossSection.StartShape.get_name() + "/" + <>c__DisplayClass41_.crossSection.EndShape.get_name());
	buildShapeExtrusion.get_transform().set_parent(<>c__DisplayClass41_.parentTransform);
	bool flag = rangeMinCurve != null && rangeMaxCurve != null;
	ModifierShapeVariableRange modifierShapeVariableRange;
	if (flag)
	{
		modifierShapeVariableRange = curvyGenerator.AddModule<ModifierShapeVariableRange>();
		modifierShapeVariableRange.Initialize();
		modifierShapeVariableRange.set_name("VariableRange_" + <>c__DisplayClass41_.sectionName + "_" + <>c__DisplayClass41_.crossSection.StartShape.get_name() + "/" + <>c__DisplayClass41_.crossSection.EndShape.get_name());
		modifierShapeVariableRange.get_transform().set_parent(<>c__DisplayClass41_.parentTransform);
		modifierShapeVariableRange.MinCurve = rangeMinCurve;
		modifierShapeVariableRange.MaxCurve = rangeMaxCurve;
		modifierShapeVariableRange.OutShape.LinkTo(buildShapeExtrusion.InCross);
	}
	else
	{
		modifierShapeVariableRange = null;
	}
	CGModuleInputSlot cGModuleInputSlot = flag ? modifierShapeVariableRange.InShape : buildShapeExtrusion.InCross;
	MorphShapes morphShapes;
	if (hasMorphing)
	{
		morphShapes = curvyGenerator.AddModule<MorphShapes>();
		morphShapes.Initialize();
		morphShapes.set_name("Morph_" + <>c__DisplayClass41_.sectionName + "_" + <>c__DisplayClass41_.crossSection.StartShape.get_name() + "/" + <>c__DisplayClass41_.crossSection.EndShape.get_name());
		morphShapes.get_transform().set_parent(<>c__DisplayClass41_.parentTransform);
		morphShapes.MorphingCurve = AnimationCurveExtension.LinearAnimationCurve;
		morphShapes.OutShape.LinkTo(cGModuleInputSlot);
	}
	else
	{
		morphShapes = null;
	}
	<HandleCrossSection>g__CreateInputShapeModules|41_0(<>c__DisplayClass41_.crossSection.StartShape, ref startOriginTranslation, ref startOriginRotation, hasMorphing ? morphShapes.InShapeA : cGModuleInputSlot, ref <>c__DisplayClass41_);
	if (hasMorphing)
	{
		<HandleCrossSection>g__CreateInputShapeModules|41_0(<>c__DisplayClass41_.crossSection.EndShape, ref endOriginTranslation, ref endOriginRotation, morphShapes.InShapeB, ref <>c__DisplayClass41_);
	}
	inputSplinePath.Path.LinkTo(buildShapeExtrusion.InPath);
	(Material, bool, string) key = (<>c__DisplayClass41_.crossSection.Material, <>c__DisplayClass41_.crossSection.IsMagnetized, <>c__DisplayClass41_.sectionName);
	if (!buildShapeExtrusions.ContainsKey(key))
	{
		buildShapeExtrusions[key] = new List<BuildShapeExtrusion>();
	}
	buildShapeExtrusions[key].Add(buildShapeExtrusion);
}

And here it is with a precondition

private void HandleCrossSection(CrossSection crossSection, bool isLeftSide, AnimationCurve rangeMinCurve, AnimationCurve rangeMaxCurve, bool hasMorphing, string sectionName, Transform parentTransform, CurvyGenerator curvyGenerator, Dictionary<CurvySpline, InputSplineShape> trackSectionCreatedShapeModules, Dictionary<(Material Material, bool IsMagnetized, string sectionName), List<BuildShapeExtrusion>> buildShapeExtrusions, ref Vector3 startOriginTranslation, ref Quaternion startOriginRotation, ref Vector3 endOriginTranslation, ref Quaternion endOriginRotation, InputSplinePath inputSplinePath)
{
	TrackGenerator_<>c__DisplayClass41_0_0 trackGenerator_<>c__DisplayClass41_0_ = default(TrackGenerator_<>c__DisplayClass41_0_0);
	trackGenerator_<>c__DisplayClass41_0_.trackSectionCreatedShapeModules = trackSectionCreatedShapeModules;
	trackGenerator_<>c__DisplayClass41_0_.<>4__this = this;
	trackGenerator_<>c__DisplayClass41_0_.sectionName = sectionName;
	trackGenerator_<>c__DisplayClass41_0_.parentTransform = parentTransform;
	trackGenerator_<>c__DisplayClass41_0_.crossSection = crossSection;
	trackGenerator_<>c__DisplayClass41_0_.isLeftSide = isLeftSide;
	System.Diagnostics.Contracts.__ContractsRuntime.Requires(rangeMinCurve != null == (rangeMaxCurve != null), null, "(rangeMinCurve != null) == (rangeMaxCurve != null)");
	<>c__DisplayClass41_0 <>c__DisplayClass41_ = default(<>c__DisplayClass41_0);
	Debug.LogWarning((object)<>c__DisplayClass41_.crossSection);
	BuildShapeExtrusion buildShapeExtrusion = curvyGenerator.AddModule<BuildShapeExtrusion>();
	buildShapeExtrusion.Resolution = 19;
	buildShapeExtrusion.CrossResolution = 30;
	buildShapeExtrusion.Optimize = false;
	buildShapeExtrusion.CrossOptimize = false;
	buildShapeExtrusion.CrossReverseNormals = false;
	buildShapeExtrusion.Initialize();
	buildShapeExtrusion.set_name("Extrusion_" + <>c__DisplayClass41_.sectionName + "_" + <>c__DisplayClass41_.crossSection.StartShape.get_name() + "/" + <>c__DisplayClass41_.crossSection.EndShape.get_name());
	buildShapeExtrusion.get_transform().set_parent(<>c__DisplayClass41_.parentTransform);
	bool flag = rangeMinCurve != null && rangeMaxCurve != null;
	ModifierShapeVariableRange modifierShapeVariableRange;
	if (flag)
	{
		modifierShapeVariableRange = curvyGenerator.AddModule<ModifierShapeVariableRange>();
		modifierShapeVariableRange.Initialize();
		modifierShapeVariableRange.set_name("VariableRange_" + <>c__DisplayClass41_.sectionName + "_" + <>c__DisplayClass41_.crossSection.StartShape.get_name() + "/" + <>c__DisplayClass41_.crossSection.EndShape.get_name());
		modifierShapeVariableRange.get_transform().set_parent(<>c__DisplayClass41_.parentTransform);
		modifierShapeVariableRange.MinCurve = rangeMinCurve;
		modifierShapeVariableRange.MaxCurve = rangeMaxCurve;
		modifierShapeVariableRange.OutShape.LinkTo(buildShapeExtrusion.InCross);
	}
	else
	{
		modifierShapeVariableRange = null;
	}
	CGModuleInputSlot cGModuleInputSlot = flag ? modifierShapeVariableRange.InShape : buildShapeExtrusion.InCross;
	MorphShapes morphShapes;
	if (hasMorphing)
	{
		morphShapes = curvyGenerator.AddModule<MorphShapes>();
		morphShapes.Initialize();
		morphShapes.set_name("Morph_" + <>c__DisplayClass41_.sectionName + "_" + <>c__DisplayClass41_.crossSection.StartShape.get_name() + "/" + <>c__DisplayClass41_.crossSection.EndShape.get_name());
		morphShapes.get_transform().set_parent(<>c__DisplayClass41_.parentTransform);
		morphShapes.MorphingCurve = AnimationCurveExtension.LinearAnimationCurve;
		morphShapes.OutShape.LinkTo(cGModuleInputSlot);
	}
	else
	{
		morphShapes = null;
	}
	<HandleCrossSection>g__CreateInputShapeModules|41_0(<>c__DisplayClass41_.crossSection.StartShape, ref startOriginTranslation, ref startOriginRotation, hasMorphing ? morphShapes.InShapeA : cGModuleInputSlot, ref <>c__DisplayClass41_);
	if (hasMorphing)
	{
		<HandleCrossSection>g__CreateInputShapeModules|41_0(<>c__DisplayClass41_.crossSection.EndShape, ref endOriginTranslation, ref endOriginRotation, morphShapes.InShapeB, ref <>c__DisplayClass41_);
	}
	inputSplinePath.Path.LinkTo(buildShapeExtrusion.InPath);
	(Material, bool, string) key = (<>c__DisplayClass41_.crossSection.Material, <>c__DisplayClass41_.crossSection.IsMagnetized, <>c__DisplayClass41_.sectionName);
	if (!buildShapeExtrusions.ContainsKey(key))
	{
		buildShapeExtrusions[key] = new List<BuildShapeExtrusion>();
	}
	buildShapeExtrusions[key].Add(buildShapeExtrusion);
}

Note that <>c__DisplayClass41_ had its fields not filled correctly in the second version

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant