Repository navigation
fix(MarketResilience): do not throw when a study is disposed before it starts - #83
Merged
Merged
Conversation
…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.
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
MarketResilienceStudyandMarketResilienceBiasStudycreate their calculator inStartAsync, butDispose(bool)disposed it unconditionally. SinceDispose(bool)became an override,BasePluginStudy.Dispose()calls it, so disposing a study that was loaded but never started throws aNullReferenceException.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 ownDisposeis idempotent, so stop-then-dispose and a second dispose behave as before.Checked
Studies.MarketResiliencebuilds (Release).