Skip to content

fix(MarketResilience): do not throw when a study is disposed before it starts - #83

Merged
silahian merged 1 commit into
masterfrom
fix/market-resilience-dispose-before-start
Oct 3, 2026
Merged

silahian merged 1 commit into
masterfrom
fix/market-resilience-dispose-before-start

Conversation

@silahian

@silahian silahian commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

What

MarketResilienceStudy and MarketResilienceBiasStudy create their calculator in StartAsync, but Dispose(bool) disposed it unconditionally. Since Dispose(bool) became an override, BasePluginStudy.Dispose() calls it, so disposing a study that was loaded but never started throws a NullReferenceException.

On application exit, PluginManager.UnloadPlugins() disposes every plugin in one loop, so that exception also stops the remaining plugins from being disposed.

Fix

Dispose the calculator only when it exists (?. on one line in each study). The calculator's own Dispose is idempotent, so stop-then-dispose and a second dispose behave as before.

Checked

  • Disposing either study before it starts, and disposing it twice, no longer throws.
  • Studies.MarketResilience builds (Release).

…t starts

Both studies create their calculator in StartAsync, but Dispose(bool)
disposed it unconditionally. Since Dispose(bool) became an override,
BasePluginStudy.Dispose() runs it, so disposing a study that was loaded
but never started threw a NullReferenceException. On application exit,
PluginManager.UnloadPlugins() disposes every plugin in one loop, so the
exception also stopped the remaining plugins from being disposed.

Dispose the calculator only when it exists. The calculator's own Dispose
is idempotent, so stop-then-dispose and a second dispose are unchanged.
Copilot AI balanced review requested due to automatic review settings October 3, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

Both null guards directly address the reported failure without changing cleanup for initialized calculators.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents disposal of never-started market resilience studies from throwing and interrupting plugin cleanup.

Changes:

  • Adds null-safe calculator disposal to both studies, preserving cleanup when calculators exist.
File Description
VisualHFT.Plugins/​Studies.MarketResilience/​MarketResilienceStudy.cs Guards disposal of mrCalc.
VisualHFT.Plugins/​Studies.MarketResilience/​MarketResilienceBiasStudy.cs Guards disposal of _mrBiasCalc.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@silahian
silahian merged commit c0a7bc4 into master Oct 3, 2026
1 check passed
@silahian
silahian deleted the fix/market-resilience-dispose-before-start branch October 3, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants