Menu

#1425 Avoid crash when cursor images are missing.

Committed
closed
nobody
5
2022-02-09
2021-12-14
No

Please add fallback to use arrow cursor:

+ (void) initialize {
    if (self == [ScintillaView class]) {
        NSBundle *bundle = [NSBundle bundleForClass: [ScintillaView class]];

        NSString *path = [bundle pathForResource: @"mac_cursor_busy" ofType: @"tiff" inDirectory: nil];
        NSImage *image = [[NSImage alloc] initWithContentsOfFile: path];
        if (image) {
            waitCursor = [[NSCursor alloc] initWithImage: image hotSpot: NSMakePoint(2, 2)];
        } else {
            NSLog(@"Wait cursor is invalid.");
            waitCursor = [[NSCursor arrow] retain];
        }

        path = [bundle pathForResource: @"mac_cursor_flipped" ofType: @"tiff" inDirectory: nil];
        image = [[NSImage alloc] initWithContentsOfFile: path];
        if (image) {
            reverseArrowCursor = [[NSCursor alloc] initWithImage: image hotSpot: NSMakePoint(15, 2)];
        } else {
            NSLog(@"Reverse arrow cursor is invalid.");
            reverseArrowCursor = [[NSCursor arrow] retain];
        }
    }
}

This may prevent crashes when the cursor is nil.

Related

Bugs: #2303

Discussion

  • Christian Schmitz

    Since ARC is used, the retain is not needed:

    + (void) initialize {
        if (self == [ScintillaView class]) {
            NSBundle *bundle = [NSBundle bundleForClass: [ScintillaView class]];
    
            NSString *path = [bundle pathForResource: @"mac_cursor_busy" ofType: @"tiff" inDirectory: nil];
            NSImage *image = [[NSImage alloc] initWithContentsOfFile: path];
            if (image) {
                waitCursor = [[NSCursor alloc] initWithImage: image hotSpot: NSMakePoint(2, 2)];
            } else {
                NSLog(@"Wait cursor is invalid.");
                // MBS fix
                waitCursor = [NSCursor arrowCursor];
            }
    
            path = [bundle pathForResource: @"mac_cursor_flipped" ofType: @"tiff" inDirectory: nil];
            image = [[NSImage alloc] initWithContentsOfFile: path];
            if (image) {
                reverseArrowCursor = [[NSCursor alloc] initWithImage: image hotSpot: NSMakePoint(15, 2)];
            } else {
                NSLog(@"Reverse arrow cursor is invalid.");
                // MBS fix
                reverseArrowCursor = [NSCursor arrowCursor];
            }
        }
    }
    
     

    Last edit: Christian Schmitz 2021-12-14
  • Neil Hodgson

    Neil Hodgson - 2021-12-14

    The underlying problem is that the image couldn't be loaded and this should be fixed instead of working around it.

    Cursor image loading was supposed to be fixed by [16f92e].

     

    Related

    Commit: [16f92e]

  • Christian Schmitz

    Well, we like to use Scintilla in our app and I'd like to make sure that the images are optional, so this can work without them.
    So please include a fallback for that case like the two lines above..

     
    • Neil Hodgson

      Neil Hodgson - 2021-12-15

      Are you using the provided Scintilla.xcodeproj project file?

       
      • Christian Schmitz

        Sure. I use it to build myself a library.

        And if the waitCursor/reverseArrowCursor would not be static, we could just prefill them on application start.

         
        • Neil Hodgson

          Neil Hodgson - 2021-12-15

          The images should be loaded on ScintillaView class load (+initialize) which occurs when Scintilla is loaded.

          I just don't understand why the image resources aren't available.

           
          • Christian Schmitz

            Because we build a library, which others use and they may not include the images.
            And the software should in my opinion simply work without them.

             
            • Neil Hodgson

              Neil Hodgson - 2021-12-15

              Because we build a library

              its unclear what you mean here. Is this a static library? Scintilla.xcodeproj builds a framework, which is a shared library plus resources (such as these images) and headers. Why wouldn't the images be included? The 'info bar' feature will also fail if its image isn't available.

              Are you deliberately removing the images because you do not like these cursors?

               
              • Christian Schmitz

                We changed the project to build a static library.
                The info bar can work fine without the image.

                For my project, I include the images, but I don't like it to crash if the user forgets the pictures.

                 
  • Neil Hodgson

    Neil Hodgson - 2022-01-13
    • labels: --> scintilla, cocoa
    • Group: Initial --> Committed
     
  • Neil Hodgson

    Neil Hodgson - 2022-01-13

    Committed as [70ba51].

    Future changes to Scintilla may add more resources which could cause crashes if not included in builds.

     

    Related

    Commit: [70ba51]

  • Neil Hodgson

    Neil Hodgson - 2022-02-09
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB