FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
0075 — kSimMgrKeyFhVisualization holds an FhVisualization or an FhVisualizationSDL, untyped
ID 0075
Class API
Severity 2
Status ready

Models: —

Found: 2026-10-22, porting fhsim_maritime to fhsim 3 (its OIS input SimObjects look up the visualization in RenderInit)

Evidence

include/fhsim/NFhSim.h:143 documents kSimMgrKeyFhVisualization as "the FhVisualization instance". Two observers register different, unrelated types under it with the untyped SetPtr:

  • src/visual/observer/VisualizationObserver.cpp:33: simMgr->SetPtr(fhsim::kSimMgrKeyFhVisualization, &m_visualization); with an FhVisualization (FhVis).
  • src/visual/observer/VisualizationSDLObserver.cpp:35: the same call with an FhVisualizationSDL (FhSimUI).

src/visual/dll/module/VisDllEntry.cpp:98 registers a third pointer under it.

Effect

A SimObject that casts the pointer to FhVisualization* (as fhsim_maritime's gamepad and console input objects must, to reach the input manager) is undefined behaviour under FhSimUI. fhsim_maritime works under FhVis only.

Possible fix

Register the visualization with SetTypedSharedResource (or under two keys, one per type), so that a typed lookup of the wrong type returns null; document which hosts provide which type.

Test that would prove it

A SimObject test that runs under each host and does the typed lookup: it gets the instance under FhVis and null, not a wrong pointer, under FhSimUI.

Risk

A crash or silent memory corruption in plugins that use the key under FhSimUI.