Skip to content

Commit a73bc16

Browse files
Fix null reference exceptions
1 parent 1386dbf commit a73bc16

File tree

6 files changed

+80
-11
lines changed

6 files changed

+80
-11
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* Band pass filter - AC simulation stepping with mc()
2+
V1 IN 0 AC 1
3+
LI IN MIDDLE {mc(0.6, tol)}
4+
C1 MIDDLE OUT {mc(10e-6, tol)}
5+
R1 OUT 0 {mc(1000, tol)}
6+
.ac oct 100 1 500
7+
.param tol=0.2
8+
.plot ac v(OUT)
9+
.end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* Band pass filter - AC simulation stepping with mc()
2+
V1 IN 0 AC 1
3+
LI IN MIDDLE {mc(0.6, tol)}
4+
C1 MIDDLE OUT {mc(10e-6, tol)}
5+
R1 OUT 0 {mc(1000, tol)}
6+
.ac oct 100 1 500
7+
.step param X 0 10 1
8+
.param tol=0.2
9+
.plot ac v(OUT) merge
10+
.end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.IO;
2+
using Xunit;
3+
4+
namespace SpiceSharpParser.IntegrationTests.Examples
5+
{
6+
public class ExampleBandPass : BaseTests
7+
{
8+
[Fact]
9+
public void When_SimulatedBandPass_Expect_NoExceptions()
10+
{
11+
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/band-pass_1.cir");
12+
var netlistContent = File.ReadAllText(path);
13+
14+
var parser = new SpiceNetlistParser();
15+
parser.Settings.Lexing.HasTitle = true;
16+
17+
var parseResult = parser.ParseNetlist(netlistContent);
18+
19+
var spiceSharpReader = new SpiceSharpReader();
20+
spiceSharpReader.Settings.ExpandSubcircuits = false;
21+
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel);
22+
23+
RunSimulations(spiceSharpModel);
24+
}
25+
26+
[Fact]
27+
public void When_SimulatedBandPass2_Expect_NoExceptions()
28+
{
29+
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/band-pass_2.cir");
30+
var netlistContent = File.ReadAllText(path);
31+
32+
var parser = new SpiceNetlistParser();
33+
parser.Settings.Lexing.HasTitle = true;
34+
35+
var parseResult = parser.ParseNetlist(netlistContent);
36+
37+
var spiceSharpReader = new SpiceSharpReader();
38+
spiceSharpReader.Settings.ExpandSubcircuits = false;
39+
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel);
40+
41+
RunSimulations(spiceSharpModel);
42+
}
43+
}
44+
}

src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
</ItemGroup>
4343

4444
<ItemGroup>
45+
<None Update="Examples\Circuits\band-pass_2.cir">
46+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
47+
</None>
48+
<None Update="Examples\Circuits\band-pass_1.cir">
49+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
50+
</None>
4551
<None Update="Examples\Circuits\example02.cir">
4652
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4753
</None>

src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,25 @@ public IEnumerable<int> InvokeEvents(IEnumerable<int> codes)
4242
switch (code)
4343
{
4444
case Simulation.BeforeValidation:
45-
EventBeforeValidation.Invoke(this, EventArgs.Empty);
45+
EventBeforeValidation?.Invoke(this, EventArgs.Empty);
4646
break;
4747

4848
case Simulation.AfterValidation:
49-
EventAfterValidation.Invoke(this, EventArgs.Empty);
49+
EventAfterValidation?.Invoke(this, EventArgs.Empty);
5050
break;
5151

5252
case Simulation.BeforeSetup:
53-
EventBeforeSetup.Invoke(this, EventArgs.Empty);
53+
EventBeforeSetup?.Invoke(this, EventArgs.Empty);
5454
break;
5555
case Simulation.AfterSetup:
56-
EventAfterSetup.Invoke(this, EventArgs.Empty);
56+
EventAfterSetup?.Invoke(this, EventArgs.Empty);
5757
break;
5858
case Simulation.BeforeUnsetup:
59-
EventBeforeUnSetup.Invoke(this, EventArgs.Empty);
59+
EventBeforeUnSetup?.Invoke(this, EventArgs.Empty);
6060
break;
6161

6262
case Simulation.BeforeExecute:
63-
EventBeforeExecute.Invoke(this, EventArgs.Empty);
63+
EventBeforeExecute?.Invoke(this, EventArgs.Empty);
6464

6565
if (this is IBiasingSimulation)
6666
{
@@ -70,7 +70,7 @@ public IEnumerable<int> InvokeEvents(IEnumerable<int> codes)
7070
break;
7171

7272
case Simulation.AfterExecute:
73-
EventAfterExecute.Invoke(this, EventArgs.Empty);
73+
EventAfterExecute?.Invoke(this, EventArgs.Empty);
7474
break;
7575

7676
case AC.ExportSmallSignal:

src/SpiceSharpParser/SpiceSharpParser.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
66
<Authors>SpiceSharp</Authors>
77
<PackageProjectUrl>https://github.com/SpiceSharp/SpiceSharpParser</PackageProjectUrl>
8-
<Copyright>Copyright 2024</Copyright>
8+
<Copyright>Copyright 2025</Copyright>
99
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1010
<RepositoryUrl>https://github.com/SpiceSharp/SpiceSharpParser</RepositoryUrl>
1111
<RepositoryType></RepositoryType>
@@ -22,7 +22,7 @@
2222
<StartupObject />
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
<LangVersion>latest</LangVersion>
25-
<Version>3.2.3</Version>
25+
<Version>3.2.4</Version>
2626
</PropertyGroup>
2727

2828
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.5|AnyCPU'">
@@ -35,10 +35,10 @@
3535
</ItemGroup>
3636

3737
<ItemGroup>
38-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
38+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
3939
<PackageReference Include="SpiceSharp" Version="3.2.3" />
4040
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
41-
<PackageReference Include="SpiceSharpGenerator" Version="1.0.7">
41+
<PackageReference Include="SpiceSharpGenerator" Version="1.0.9">
4242
<PrivateAssets>all</PrivateAssets>
4343
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4444
</PackageReference>

0 commit comments

Comments
 (0)