KeyWorksRW / wxUiEditor

RAD tool used to create and maintain wxWidgets UI elements.
Apache License 2.0
63 stars 7 forks source link

Bug: Crash when setting BookPage bitmap Art to value for which internal artprovider has no image #1359

Closed Jofagi closed 7 months ago

Jofagi commented 8 months ago

Description:

I'm trying out https://github.com/perazz/wxMaterialDesignArtProvider and therefore am using wxART_-IDs that wxUiEditor does not know about. Aside from not displaying the icons, this seems to mostly work with wxUiEditor, except for BookPage bitmaps.

  1. Create a wxNoteBook and a BookPage
  2. Set bitmap.type to "Art"
  3. Set bitmap.id to a value that isn't known to wxUiEditor's internal artprovider, e.g. "wxART_SETTINGS_APPLICATIONS|wxART_OTHER"
  4. As soon as pressing enter, the application crashes/asserts (depending on build type).

I looked at the source: In gen_book_utils.cpp AddBookImageList() calls as_wxBitmapBundle() and adds the result to bundle_list. If I change the code to push_back() only if the bundle IsOk(), this results in shifted bitmaps in case there are multiple BookPages, so that's probably not a good fix. It would need a placeholder bundle or something like that...

Randalphwa commented 8 months ago

The crash occurs in wxImage::InitAlpha() when it tries to access M_IMGDATA->m_alpha. The call is made in wxImageList::GetImageListBitmaps(), in particular:

        wxImage img = bmp.ConvertToImage();
        if ( !img.HasAlpha() )
            img.InitAlpha();  <-- crash occurs in this function

That code in turn was called because there was no check for the supplied bitmap being valid.

This means that there are two parts needed for the fix. One is to add a check for a valid bitmap in wxImageList::GetImageListBitmap() and if that prevents the crash, then I can submit a PR to fix that in the wxWidgets code. The second part is for the Mockup code to verify that the art file is valid before trying to use it, and supply our standard question mark file if it isn't. That would prevent the crash in wxUiEditor, but there also needs to be a solution for code generation -- otherwise the generated code will still crash if an id is specified that doesn't exist at compile time.

Marking as high priority because of the crash.

Any fix should also be verified against the additional IDs available to Unix builds -- i.e., update one or more of the dialogs in the sdi project file (part of the wxUiTesting repository), then verify that it doesn't crash under Windows where the ids aren't available.

Randalphwa commented 8 months ago

Starting with the Daily build on 1/2/2024, wxUiEditor should no longer crash, and instead will use a placeholder image.

I'm leaving the issue open because the wxWidgets side of the crash still needs to be fixed.

Randalphwa commented 7 months ago

I've submitted a PR to wxWidgets to also prevent the crash, so combined with the fix in wxUiEditor I'm considering the issue resolved.