Skip to content

[com5] Fix com5 bug on windows plus inconsistencies in code#1274

Merged
fso42 merged 5 commits into
masterfrom
fixSSLBug
May 18, 2026
Merged

[com5] Fix com5 bug on windows plus inconsistencies in code#1274
fso42 merged 5 commits into
masterfrom
fixSSLBug

Conversation

@fso42
Copy link
Copy Markdown
Contributor

@fso42 fso42 commented May 13, 2026

Reported by CT (com5 hang on althof testcase). During analysis other problems cropped up, which are fixed now

Summary

Fixes several bugs in com1DFA discovered during simulations: circular reference in stopped particles, stale bond indices after particle removal, out-of-bounds
heap corruption from mismatched test array sizes, plus hardening against NaN/div-by-zero in reprojection.

Changes

1. Remove circular reference in stoppedParticles (9f83630)

particles["stoppedParticles"] = particles created a self-referencing dict that overwrote the correct stopped-particle arrays (x, y, m, ID) with full
flowing-particle data. Downstream in updateFieldsC this caused stopped mass rasters to use flowing instead of stopped masses. It also prevented garbage
collection and broke serialization. The line was removed; stoppedParticles is already correctly populated earlier.

2. Remap bond indices after particle removal (e425c76)

removedBonds now builds an old-to-new particle index mapping and remaps both bondStart (reindexed by new particle indices) and bondPart (target indices
remapped). removePart skips bond keys since they are already rebuilt. Previously bondPart stored original indices that became stale after np.extract
compacted arrays, causing silent data corruption or out-of-bounds access.

3. Fix division-by-zero in distConservProjectionIteratrive (f47629a)

Added distn == 0 guard before dist / distn to prevent NaN for stopped particles.

4. Ensure arrays returned by updateFieldsC are owned copies (ab23111)

Multiple fields and particles assignments now use .copy() when converting to np.asarray, preventing issues with memory views that could lead to
dangling references or double-free (BUG COM5). Adjusted bondDist handling to avoid problematic views during inplace modification. Added tests verifying
owndata=True and base is None.

@fso42 fso42 self-assigned this May 13, 2026
@fso42 fso42 added the bugfix label May 13, 2026
@qltysh
Copy link
Copy Markdown
Contributor

qltysh Bot commented May 13, 2026

Analysis for project AvaFrame

❌ 1 blocking issue (1 total)

Tool Category Rule Count
black Style Incorrect formatting, autoformat by running qlty fmt. 1

@qltysh one-click actions:

  • Auto-fix formatting (qlty fmt && git push)

@qltysh
Copy link
Copy Markdown
Contributor

qltysh Bot commented May 13, 2026

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Components (1)

RatingComponent% Diff
Coverage rating: C Coverage rating: C
com1DFA100.0%

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
Coverage rating: F Coverage rating: F
avaframe/com1DFA/particleTools.py100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@fso42 fso42 changed the title [com5] Fix ssl bug on windows plus inconsistencies in code [com5] Fix com5 bug on windows plus inconsistencies in code May 13, 2026
fso42 and others added 5 commits May 18, 2026 16:08
…ies (BUG COM5)

- Updated multiple `fields` and `particles` assignments to ensure `.copy()` is used when converting to `np.asarray`, preventing potential issues with memory views.
- Adjusted handling of `bondDist` to avoid creating problematic views during inplace modifications.
- Added tests to verify that arrays returned by `updateFieldsC` have `owndata=True` and no base reference.
…atrive

Add distn==0 guard before dist/distn to prevent NaN for stopped particles.
removedBonds now builds old-to-new particle index mapping and remaps
both bondStart (reindexed by new particle indices) and bondPart
(target indices remapped). removePart skips bond keys since they are
already correctly rebuilt by removedBonds.

Previously bondPart stored original indices that became stale after
np.extract compacted particle arrays, causing silent data corruption
or out-of-bounds access when particles exited the domain.
particles["stoppedParticles"] = particles created a self-referencing
dict that overwrote the correct stopped-particle arrays (x, y, m, ID)
with the full flowing-particle data. Downstream in updateFieldsC this
caused stopped mass rasters to use flowing instead of stopped masses.
Also prevented garbage collection and broke serialization.

Removed the offending line. stoppedParticles is already correctly
populated earlier in the function, and massStopped captures the
accumulated total.
…ionsCython`

Updated array initializations (`pfv`, `ppr`, `pft`, `pta`, `pke`) to use dynamic dimensions based on `header["nrows"]` and `header["ncols"]` instead of static `(1, 1)` arrays. This ensures compatibility with test inputs of varying sizes.
@fso42
Copy link
Copy Markdown
Contributor Author

fso42 commented May 18, 2026

Standardtests ident, apart from known com5 com1(timedep)

@fso42 fso42 merged commit a3ce5f9 into master May 18, 2026
4 checks passed
@fso42 fso42 deleted the fixSSLBug branch May 18, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant