FLTK logo

[fltk.general] Re: Specific issue with macOS drawRect

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Specific issue with macOS drawRect "anmol.... Jul 22, 2021  
  For my own reference, I get a warning here - 
NSOpenGLContext deprecated. For some odd reason, Xcode is defining __OBJC__

#ifdef __OBJC__

  @class NSOpenGLContext;

  typedef NSOpenGLContext* GLContext;

#elif defined(__cplusplus)

  typedef class NSOpenGLContext* GLContext;

#endif /* __OBJC__ */


On Thursday, July 22, 2021 at 10:49:52 PM UTC+5:30 anmol....@gmail.com wrote:
I ended up using CFUserNotification from CoreFoundation directly. I am going to revisit this in a few weeks to see if there is still a problem.

On Monday, July 19, 2021 at 12:56:50 PM UTC+5:30 Manolo wrote:
Le dimanche 18 juillet 2021 à 00:55:38 UTC+2, anmol....@gmail.com a écrit :
I have a Fl_wizard window that runs fine in a very simple test app. As a part of a larger project, it just goes gray and most of the widgets disappear if I click on any field.

Tracing this in Xcode gives an error related to the same macOS code mentioned above. 

CGBitmapContextGetWidth: invalid context 0x600003722340. 

Backtrace:

  <CGBitmapContextGetWidth+49>

   <-[FLView create_aux_bitmap:retina:]+55>

    <-[FLView drawRect:]+360>

 …etc…


The crash is when FLTK function create_aux_bitmap calls macOS function CGBitmapContextGetWidth.
Here is that FLTK function:
- (void)create_aux_bitmap:(CGContextRef)gc retina:(BOOL)r {
  if (!gc || fl_mac_os_version >= 101600) {
    // bitmap context-related functions (e.g., CGBitmapContextGetBytesPerRow) can't be used here with macOS 11.0 "Big Sur"
    static CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
    int W = [self frame].size.width, H = [self frame].size.height;
    if (r) { W *= 2; H *= 2; }
    aux_bitmap = CGBitmapContextCreate(NULL, W, H, 8, 0, cspace, kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Host);
  } else {
    aux_bitmap = CGBitmapContextCreate(NULL, CGBitmapContextGetWidth(gc), CGBitmapContextGetHeight(gc),
                                       CGBitmapContextGetBitsPerComponent(gc), CGBitmapContextGetBytesPerRow(gc),
                                       CGBitmapContextGetColorSpace(gc), CGBitmapContextGetBitmapInfo(gc));
  }
  if (r) CGContextScaleCTM(aux_bitmap, 2, 2);
}

When running macOS 11 or above, the first part of the if MUST be chosen, which avoids
a call to CGBitmapContextGetWidth() that faults with these macOS versions.
Thus, either you run an older version of FLTK (Sorry, I insist because this has happened
so many times with systems containing various FLTK source trees),  or global variable fl_mac_os_version is not properly initialized.
Its value should be 1015xx on macOS 10.15, or 101600 or 11xxyy on macOS 11.
Please, have its value printed out before your program creates its first FLTK window.
It's enough to declare it with :
  extern int fl_mac_os_version;

fl_mac_os_version is assigned either as a static initializer, or when FLTK opens the display.
But if that's not enough in your special setting that mixes FLTK and non-FLTK windows,
you can force its initialization calling FLTK's public function fl_open_display() early in your program.
This requires :
#include <FL/platform.H>

Let me know, please, if it's getting better with that cure.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/95be4342-7b23-47a2-8e14-3d2c4623129dn%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.