[Fix] check a wxMenuItem raises error msg box#2526
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an error message issue by adding an extra validation check (using GetMenu()) before calling the Check() method on wxMenuItem pointers to avoid using detached or invalid menu items. Key changes include:
- Updating version values in version.h.
- Adding an additional check (mi->GetMenu()) in multiple files.
- Fixing a syntax error in Explore/HistogramView.cpp.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| version.h | Updated version_subbuild, month, and day values for the release. |
| TemplateLegend.cpp | Added GetMenu() check before calling Check() on wxMenuItem. |
| GeoDa.cpp | Added GetMenu() check to validate menu items before checking them. |
| GeneralWxUtils.cpp | Added GetMenu() check before performing Check() on menu items. |
| Explore/.cpp and DataViewer/.cpp | Added GetMenu() check to ensure menu is attached before calling Check(). |
| Explore/HistogramView.cpp | Introduces a syntax error with an extra arrow in the GetMenu() call. |
e2410ac to
9f8806c
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue where calling Check() on a wxMenuItem that isn’t attached to a menu could lead to errors. The main changes introduce an additional condition (mi->GetMenu()) before checking or modifying menu items, and some auxiliary version and workflow updates.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| version.h | Bumps version numbers to reflect updated build information |
| TemplateLegend.cpp | Adds a GetMenu() check before calling Check() on a wxMenuItem |
| GeoDa.cpp | Updates Check() calls with GetMenu() guard for encoding menu items |
| GeneralWxUtils.cpp | Adds GetMenu() validation in the CheckMenuItem helper function |
| Explore/ScatterNewPlotView.cpp | Updates Check() condition with GetMenu() in time variant options |
| Explore/PCPNewView.cpp | Adds GetMenu() verification before checking time synchronization |
| Explore/MapNewView.cpp | Enhances menu item checks with GetMenu() for basemap selection |
| Explore/MapLayerTree.cpp | Updates right-click checkable items with an additional GetMenu() check |
| Explore/LisaScatterPlotView.cpp | Includes GetMenu() guard for time variant option check |
| Explore/HistogramView.cpp | Adds GetMenu() condition when checking time variant options |
| Explore/ConditionalNewView.cpp | Improves Check() calls by verifying the menu item's attachment |
| Explore/CartogramNewView.cpp | Adds GetMenu() validation in time synchronization options |
| Explore/BoxNewPlotView.cpp | Enforces attachment check (GetMenu()) before calling Check() |
| Explore/3DPlotView.cpp | Adds the GetMenu() condition to safely check synchronization menu items |
| DataViewer/TableFrame.cpp | Updates encoding menu item checks to include a GetMenu() guard |
| .github/workflows/* | Upgrades GitHub Actions versions for checkout, cache, and upload steps |
Comments suppressed due to low confidence (14)
TemplateLegend.cpp:227
- The added GetMenu() check ensures the wxMenuItem is attached to a menu. Verify that this condition reliably prevents errors when the menu item is detached.
if (mi && mi->IsCheckable() && mi->GetMenu()) {
GeoDa.cpp:7053
- Adding the GetMenu() check helps ensure that Check() is only called on menu items with a valid parent. Confirm that this pattern covers all scenarios where a dangling pointer could occur.
if (menu && menu->IsCheckable() && menu->GetMenu()) menu->Check(e==wxFONTENCODING_UTF8);
GeneralWxUtils.cpp:438
- The additional check for GetMenu() is appropriate to avoid operating on a detached menu item. Ensure this guard is consistently used throughout the codebase for safety.
if (mi && mi->IsCheckable() && mi->GetMenu()) {
Explore/ScatterNewPlotView.cpp:358
- The update ensures that Check() is called only if the menu item is still attached. Confirm that var_info[i].sync_with_global_time is maintained correctly for detached items.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
Explore/PCPNewView.cpp:213
- Ensure that the added GetMenu() check properly prevents Check() from being called on a menu item that is not attached.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
Explore/MapNewView.cpp:1460
- The modification adds a safeguard to ensure the item is attached before invoking Check(). Verify this meets all cases where the menu item might be detached.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
Explore/MapLayerTree.cpp:841
- The inclusion of the GetMenu() check adds robustness to prevent operations on detached menu items. Confirm that this change handles all right-click scenarios correctly.
if (outline && outline->IsCheckable() && outline->GetMenu()) {
Explore/LisaScatterPlotView.cpp:143
- The updated condition ensures the menu item is valid before calling Check(). Verify that this change aligns with the intended behavior of the time variant options.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
Explore/HistogramView.cpp:300
- Adding the GetMenu() check is a good safeguard against calling Check() on a potentially detached item. Ensure that this condition is sufficient under all operating conditions.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[0].sync_with_global_time);
Explore/ConditionalNewView.cpp:224
- This change prevents Check() from being invoked on an unattached menu item. Confirm that this pattern is adequate for handling detached menu scenarios.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
Explore/CartogramNewView.cpp:295
- The additional GetMenu() condition enhances safety when calling Check(). Verify that this update addresses all potential issues with detached wxMenuItems.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
Explore/BoxNewPlotView.cpp:181
- The updated condition ensures that the box plot’s time variant option is only toggled if the menu item is still attached to a menu. Confirm that this check fully prevents errors from detached items.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[0].sync_with_global_time);
Explore/3DPlotView.cpp:180
- By adding the GetMenu() check, the code properly avoids calling Check() on a detached menu item. Verify that this condition covers all edge cases for 3D plot synchronization.
if (mi && mi->IsCheckable() && mi->GetMenu()) mi->Check(var_info[i].sync_with_global_time);
DataViewer/TableFrame.cpp:285
- The enhanced condition ensures that encoding menu items are only updated when still attached. Confirm that this change reliably prevents errors from detached menu items in the TableFrame.
if (menu && menu->IsCheckable() && menu->GetMenu()) menu->Check(e==wxFONTENCODING_UTF8);
Check if the wxMenuItem* is non-null before calling Check(). However, this might be not enough:
This PR tries to fix it by:
For example, for wxMenuItem, use GetMenu() (returns the parent menu or nullptr):