Skip to content

Fix segfault with ZoneControl:ContaminantController - #11709

Open
joseph-robertson wants to merge 4 commits into
developfrom
contam-segfault
Open

Fix segfault with ZoneControl:ContaminantController#11709
joseph-robertson wants to merge 4 commits into
developfrom
contam-segfault

Conversation

@joseph-robertson

@joseph-robertson joseph-robertson commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Pull request overview

Description of the purpose of this PR

Pull Request Author

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies
  • If adding/removing any output files (e.g., eplustbl.*)
    • Update ..\scripts\Epl-run.bat
    • Update ..\scripts\RunEPlus.bat
    • Update ..\src\EPLaunch\ MainModule.bas, epl-ui.frm, and epl.vbp (VersionComments)
    • Update ...github\workflows\energyplus.py

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@joseph-robertson joseph-robertson self-assigned this Jul 24, 2026
@joseph-robertson joseph-robertson added the Defect Includes code to repair a defect in EnergyPlus label Jul 24, 2026
state.dataContaminantBalance->ZoneCO2SetPoint(ZoneNum) =
state.dataContaminantBalance->ContaminantControlledZone(Loop).setptSched->getCurrentVal();
if (state.dataContaminantBalance->ContaminantControlledZone(Loop).setptSched == nullptr) {
state.dataContaminantBalance->ZoneCO2SetPoint(ZoneNum) = 0.0;

@joseph-robertson joseph-robertson Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think this maintains previous behavior (e.g., v24.2 initialized SPSchedIndex to zero) before use of getCurrentVal(). I suppose the alternative to this fix is to fatal and require that the schedule be populated?

\paragraph{Field:Carbon Dioxide Setpoint Schedule Name}\label{fieldcarbon-dioxide-setpoint-schedule-name}

This field contains the name of a schedule that contains the zone carbon dioxide concentration setpoint as a function of time. The units for carbon dioxide setpoint are ppm. The setpoint values in the schedule must be between 0 and 2000 ppm. . This field is used when the field System Outdoor Air Method = IndoorAirQualityProcedure in the \hyperref[controllermechanicalventilation]{Controller:MechanicalVentilation} object.
This field contains the name of a schedule that contains the zone carbon dioxide concentration setpoint as a function of time. The units for carbon dioxide setpoint are ppm. The setpoint values in the schedule must be between 0 and 2000 ppm. This field is used when the field System Outdoor Air Method = IndoorAirQualityProcedure in the \hyperref[controllermechanicalventilation]{Controller:MechanicalVentilation} object.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should description for Carbon Dioxide Setpoint Schedule Name (and Generic Contaminant Setpoint Schedule Name) be updated to include language about being used when field Carbon Dioxide Concentration (and Generic Contaminant Concentration) is Yes on the ZoneAirContaminantBalance object?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a crash in the zone contaminant control initialization path by guarding access to optional contaminant setpoint schedules, and updates the Input Output Reference text to better describe when those schedules are used.

Changes:

  • Add nullptr checks before dereferencing CO₂ and generic contaminant setpoint schedule pointers in InitZoneContSetPoints.
  • Default the zone setpoint value when a schedule pointer is missing to avoid a segfault.
  • Update IO Reference text to clarify the contexts in which the setpoint schedule fields are used.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/EnergyPlus/ZoneContaminantPredictorCorrector.cc Adds null-guarding around contaminant setpoint schedule dereferences to prevent segfaults.
doc/input-output-reference/src/overview/group-zone-controls-thermostats.tex Clarifies documentation around CO₂/GC setpoint schedule field usage conditions.
Suppressed comments (2)

src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:1445

  • When the generic contaminant setpoint schedule pointer is null, the fallback setpoint of 0.0 can unintentionally trigger any logic that treats ZoneAirGC > ZoneGCSetPoint as a control threshold (similar to the CO2 case), leading to non-obvious behavior changes. Consider using a large sentinel (Constant::BigNumber) to effectively disable the threshold when the schedule is absent, or report a clear input error.
            if (state.dataContaminantBalance->ContaminantControlledZone(Loop).genericContamSetptSched == nullptr) {
                state.dataContaminantBalance->ZoneGCSetPoint(ZoneNum) = 0.0;
            } else {
                state.dataContaminantBalance->ZoneGCSetPoint(ZoneNum) =
                    state.dataContaminantBalance->ContaminantControlledZone(Loop).genericContamSetptSched->getCurrentVal();

src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:1432

  • The new nullptr handling for contaminant setpoint schedules fixes a crash-prone path, but there is no unit test exercising the missing-schedule case to prevent regressions. Consider adding a test in tst/EnergyPlus/unit/ZoneContaminantPredictorCorrector.unit.cc that sets CO2Simulation/GenericContamSimulation true with a controlled zone whose setpoint schedule pointers are null, and verifies InitZoneContSetPoints completes without crashing and produces the expected fallback behavior.
            if (state.dataContaminantBalance->ContaminantControlledZone(Loop).setptSched == nullptr) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1432 to +1437
if (state.dataContaminantBalance->ContaminantControlledZone(Loop).setptSched == nullptr) {
state.dataContaminantBalance->ZoneCO2SetPoint(ZoneNum) = 0.0;
} else {
state.dataContaminantBalance->ZoneCO2SetPoint(ZoneNum) =
state.dataContaminantBalance->ContaminantControlledZone(Loop).setptSched->getCurrentVal();
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hm I'm not really sure about this one. Is this not a deviation from previous (before the getCurrentVal() change) behavior?

Comment on lines 1200 to +1202
\paragraph{Field:Carbon Dioxide Setpoint Schedule Name}\label{fieldcarbon-dioxide-setpoint-schedule-name}

This field contains the name of a schedule that contains the zone carbon dioxide concentration setpoint as a function of time. The units for carbon dioxide setpoint are ppm. The setpoint values in the schedule must be between 0 and 2000 ppm. . This field is used when the field System Outdoor Air Method = IndoorAirQualityProcedure in the \hyperref[controllermechanicalventilation]{Controller:MechanicalVentilation} object.
This field contains the name of a schedule that contains the zone carbon dioxide concentration setpoint as a function of time. The units for carbon dioxide setpoint are ppm. The setpoint values in the schedule must be between 0 and 2000 ppm. This field is used when the field System Outdoor Air Method = IndoorAirQualityProcedure in the \hyperref[controllermechanicalventilation]{Controller:MechanicalVentilation} object and the field Carbon Dioxide Concentration = Yes in the \hyperref[zoneaircontaminantbalance]{ZoneAirContaminantBalance} object.
Comment on lines 1216 to +1218
\paragraph{Field: Generic Contaminant Setpoint Schedule Name}\label{field-generic-contaminant-setpoint-schedule-name}

This field contains the name of a schedule that contains the zone generic contaminant concentration setpoint as a function of time. The units for generic contaminant setpoint are ppm. The setpoint values in the schedule must be\textgreater{} = 0.
This field contains the name of a schedule that contains the zone generic contaminant concentration setpoint as a function of time. The units for generic contaminant setpoint are ppm. The setpoint values in the schedule must be \textgreater{}= 0. This field is used when the field Generic Contaminant Concentration = Yes in the \hyperref[zoneaircontaminantbalance]{ZoneAirContaminantBalance} object.
@joseph-robertson
joseph-robertson marked this pull request as ready for review August 3, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Defect Includes code to repair a defect in EnergyPlus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants