Skip to content

Commit 8b7392b

Browse files
committed
Fixed crash trying to instantiate forms objects.
1 parent 2272de4 commit 8b7392b

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

FRBDK/Glue/GumPlugin/GumPlugin/CodeGeneration/GueDerivingClassCodeGenerator.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,29 @@ public void GenerateConstructor(ElementSave elementSave, ICodeBlock currentBlock
510510

511511
bool hasBase = !string.IsNullOrEmpty(elementSave.BaseType);
512512

513-
if(hasBase)
513+
string throwaway;
514+
var thisIsAFormsObject =
515+
GetIfShouldGenerateFormsCode(elementSave, out throwaway) || FormsClassCodeGenerator.Self.GetIfShouldGenerate(elementSave);
516+
517+
if (hasBase)
514518
{
515-
baseCall = "base(false, tryCreateFormsObject)";
519+
// If this is a Forms object, then it should NOT try to create a forms object at the base level
520+
if(thisIsAFormsObject)
521+
{
522+
// don't generate at the base, do it here at the derived
523+
baseCall = "base(false, false)";
524+
}
525+
else
526+
{
527+
baseCall = "base(false, tryCreateFormsObject)";
528+
}
516529
}
517530
var constructor = currentBlock.Constructor("public", runtimeClassName, "bool fullInstantiation = true, bool tryCreateFormsObject = true", baseCall );
518531

519532
// This may not have a value, so if not, don't set it:
520533
var state = elementSave.DefaultState;
521534

522-
string throwaway;
523-
if (GetIfShouldGenerateFormsCode(elementSave, out throwaway) || FormsClassCodeGenerator.Self.GetIfShouldGenerate(elementSave))
535+
if (thisIsAFormsObject)
524536
{
525537
constructor.Line("this.tryCreateFormsObject = tryCreateFormsObject;");
526538
}

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Content/GumProject/Components/UserControlDerived.gucx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
<Category>Rendering</Category>
3333
<SetsValue>true</SetsValue>
3434
</Variable>
35+
<Variable>
36+
<Type>float</Type>
37+
<Name>ButtonInstance.Width</Name>
38+
<Value xsi:type="xsd:float">124</Value>
39+
<SetsValue>true</SetsValue>
40+
</Variable>
41+
<Variable>
42+
<Type>float</Type>
43+
<Name>ButtonInstance.X</Name>
44+
<Value xsi:type="xsd:float">13</Value>
45+
<SetsValue>true</SetsValue>
46+
</Variable>
47+
<Variable>
48+
<Type>float</Type>
49+
<Name>ButtonInstance.Y</Name>
50+
<Value xsi:type="xsd:float">17</Value>
51+
<SetsValue>true</SetsValue>
52+
</Variable>
3553
<Variable>
3654
<Type>ChildrenLayout</Type>
3755
<Name>ChildrenLayout</Name>
@@ -236,5 +254,10 @@
236254
<BaseType>DefaultForms/ColoredFrame</BaseType>
237255
<DefinedByBase>true</DefinedByBase>
238256
</Instance>
257+
<Instance>
258+
<Name>ButtonInstance</Name>
259+
<BaseType>DefaultForms/Button</BaseType>
260+
<DefinedByBase>false</DefinedByBase>
261+
</Instance>
239262
<Behaviors />
240263
</ComponentSave>

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/TestProjectDesktopNet6.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,7 @@
20532053
<Compile Include="Factories\VariantEntityBaseFactory.Generated.cs" />
20542054
<Compile Include="Factories\VariantEntityDerivedFactory.Generated.cs" />
20552055
<Compile Include="FileAliases.Generated.cs" />
2056+
<Compile Include="Forms\Components\UserControlDerivedForms.Generated.cs" />
20562057
<Compile Include="Forms\Controls\CustomUserControl.cs" />
20572058
<Compile Include="Forms\Screens\BaseGlueScreenNotBaseGumForms.Generated.cs" />
20582059
<Compile Include="Forms\Screens\DerivedOfDerivedScreenGumForms.Generated.cs" />

0 commit comments

Comments
 (0)