Skip to content
Draft
2 changes: 1 addition & 1 deletion .github/actions/testgrid/testmacos.tcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
testgrid -outdir results/macos-x64 caf basic
testgrid -outdir results/macos-x64 "caf,helix" "basic,standard"
16 changes: 16 additions & 0 deletions src/Draw/TKDraw/Draw/Draw_Window_1.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ static Standard_Integer getScreenBottom()
{
Cocoa_LocalPool aLocalPool;

// Suppress Metal initialization errors on macOS by pre-warming graphics context
static bool isMetalInitialized = false;
if (!isMetalInitialized) {
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static boolean variable isMetalInitialized is not thread-safe. If this function can be called from multiple threads, consider using std::once_flag with std::call_once or adding proper synchronization to prevent race conditions during Metal initialization.

Suggested change
static bool isMetalInitialized = false;
if (!isMetalInitialized) {
static std::once_flag metalInitFlag;
std::call_once(metalInitFlag, []() {

Copilot uses AI. Check for mistakes.
@try {
// Create a minimal NSImage to trigger Metal initialization early
NSImage* aTempImage = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)];
[aTempImage lockFocus];
[aTempImage unlockFocus];
[aTempImage release];
}
@catch (NSException*) {
// Ignore any Metal initialization exceptions
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching all NSException types without specifying the exception type or logging the error could hide important debugging information. Consider logging the exception details or catching more specific exception types to aid in troubleshooting Metal initialization issues.

Suggested change
@catch (NSException*) {
// Ignore any Metal initialization exceptions
@catch (NSException* exception) {
// Log Metal initialization exceptions for debugging purposes
NSLog(@"Metal initialization failed with exception: %@ - %@", [exception name], [exception reason]);

Copilot uses AI. Check for mistakes.
}
isMetalInitialized = true;
}

// converting left-bottom coordinate to left-top coordinate
Standard_Integer anYTop = getScreenBottom() - theXY.y() - theSize.y();

Expand Down
Loading