fix: protect async preview lifetime and validate real canvas and spatial tools

这个提交包含在:
mac 于 2026-11-05 01:42:34 +08:00 提交
1 父节点 a3bd2ceb26
当前提交 1c3e294ce9
18 个文件已更改
+151 -45

没有与搜索条件相匹配的文件

+7 -3
查看文件
@@ -12,6 +12,7 @@
#import "DYInspector.h"
#import "DYTheme.h"
#include "DYSpiderState.h"
#include "DYToolGPU.h"
#include <string>
#import <CoreVideo/CoreVideo.h>
#import <IOSurface/IOSurface.h>
@@ -141,6 +142,7 @@ struct Run {
bool passed=true;
void record(NSString *name,bool ok,NSDictionary *details=nil) {
NSMutableDictionary *row=[NSMutableDictionary dictionaryWithDictionary:details?:@{}];
if(getenv("DAYU_DIAGNOSTICS_PROGRESS"))fprintf(stderr,"%s %s\n",ok?"PASS":"FAIL",name.UTF8String);
row[@"name"]=name;row[@"pass"]=@(ok);[rows addObject:row];if(!ok)passed=false;
}
void need(NSString *name,bool ok,NSDictionary *details=nil) {
@@ -249,8 +251,8 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
DYDiagnosticManager *uiHost=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(uiHost,nil);
DYInspector *inspector=[[[DYInspector alloc]initWithAPIManager:uiHost]autorelease];[inspector refresh];
NSArray *cards=[inspector valueForKey:@"cards"];BOOL initialUI=YES;
for(NSDictionary *card in cards)initialUI&=([card[@"collapsed"]boolValue]!=[@[@"primary",@"spider",@"base"]containsObject:card[@"section"][@"key"]])&&[(NSButton*)card[@"enabled"]state]==NSControlStateValueOn;
run.record(@"default-primary-spider-base-expanded-all-eyes-on",initialUI,@{@"modules":@(cards.count)});
for(NSDictionary *card in cards){BOOL expected=[@[@"primary",@"spider",@"base",@"hsl"]containsObject:card[@"section"][@"key"]];initialUI&=[card[@"collapsed"]boolValue]&&[card[@"removed"]boolValue]!=expected;}
run.record(@"default-only-primary-spider-base-hsl-visible-and-collapsed",initialUI,@{@"modules":@(cards.count)});
DYUniforms uiBefore,uiAfter;DYReadUniforms(uiHost,kCMTimeZero,&uiBefore);BOOL foldingIndependent=YES;
for(NSDictionary *card in cards){NSButton *header=card[@"header"];BOOL was=[card[@"collapsed"]boolValue];[header performClick:nil];[inspector refresh];DYReadUniforms(uiHost,kCMTimeZero,&uiAfter);foldingIndependent&=[card[@"collapsed"]boolValue]!=was&&memcmp(&uiBefore,&uiAfter,sizeof(uiBefore))==0;[header performClick:nil];[inspector refresh];}
run.record(@"all-disclosure-actions-preserve-every-render-parameter",foldingIndependent);
@@ -272,7 +274,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
NSWindow *interactionWindow=[[[NSWindow alloc]initWithContentRect:NSMakeRect(0,0,400,780) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]autorelease];interactionWindow.contentView=inspector;[inspector layoutSubtreeIfNeeded];
NSArray *graphics=[inspector valueForKey:@"graphics"];NSView *wheel=nil;for(NSView *graphic in graphics)if([NSStringFromClass(graphic.class)isEqual:@"DYPrimaryBalanceWheel"])wheel=graphic;
run.need(@"primary-balance-wheel-restored-and-palette-loaded",wheel&&[wheel valueForKey:@"wheel"]!=nil);
BOOL merged=cards.count==14&&[cards[0][@"section"][@"key"]isEqual:@"primary"]&&[cards[1][@"section"][@"key"]isEqual:@"spider"];for(NSDictionary *card in cards)merged&=![@[@"input",@"output"]containsObject:card[@"section"][@"key"]];
BOOL merged=cards.count==DYToolTypes().count&&[cards[0][@"section"][@"key"]isEqual:@"primary"]&&[cards[1][@"section"][@"key"]isEqual:@"spider"];for(NSDictionary *card in cards)merged&=![@[@"input",@"output"]containsObject:card[@"section"][@"key"]];
NSDictionary *controls=[inspector valueForKey:@"controls"];for(NSDictionary *record in controls.allValues)merged&=![[record[@"descriptor"]objectForKey:@"key"]hasPrefix:@"cmbypass"];
run.record(@"single-primary-card-no-bypass-checkboxes",merged);
auto mouseFor=[&](NSView *view,NSEventType type,NSPoint point,NSEventModifierFlags flags=0,NSInteger clicks=1){return [NSEvent mouseEventWithType:type location:[view convertPoint:point toView:nil] modifierFlags:flags timestamp:0 windowNumber:interactionWindow.windowNumber context:nil eventNumber:0 clickCount:clicks pressure:type==NSEventTypeLeftMouseUp?0:1];};
@@ -305,6 +307,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
[disc resetMesh];NSData *beforeCancel=[[disc.meshData copy]autorelease];NSPoint anchor=[disc point:2];[disc mouseDown:mouseFor(disc,NSEventTypeLeftMouseDown,anchor)];[disc mouseDragged:mouseFor(disc,NSEventTypeLeftMouseDragged,NSMakePoint(anchor.x+10,anchor.y+5))];[disc keyDown:[NSEvent keyEventWithType:NSEventTypeKeyDown location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:interactionWindow.windowNumber context:nil characters:@"\x1b" charactersIgnoringModifiers:@"\x1b" isARepeat:NO keyCode:53]];run.record(@"spider-escape-restores-coordinates-and-pins",[beforeCancel isEqual:disc.meshData]);
run.record(@"native-interaction-window-never-visible",!interactionWindow.visible);[inspector resetAll:nil];[inspector refresh];
id<MTLDevice> gpu=MTLCreateSystemDefaultDevice();run.need(@"metal-device",gpu!=nil);gpuName=gpu.name;
defaults.skinFaceOnly=0; // legacy point-color and Cube reference suite
const NSUInteger width=64,height=48;DYDiagnosticTile *source=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease],*destination=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease];
run.need(@"real-iosurface-image-tiles",source&&destination&&source.ioSurface&&destination.ioSurface);
Pixels input(width*height*4);for(NSUInteger y=0;y<height;y++)for(NSUInteger x=0;x<width;x++){size_t p=(y*width+x)*4;float alpha=float((x+y)%5)/4.f;input[p]=(__fp16)((.08f+.75f*float(x)/(width-1))*alpha);input[p+1]=(__fp16)((.05f+.8f*float(y)/(height-1))*alpha);input[p+2]=(__fp16)((.1f+.65f*float((x*7+y*3)%64)/63.f)*alpha);input[p+3]=(__fp16)alpha;}
@@ -511,6 +514,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
#include "DYCompactUIDiagnostics.inc.h"
#include "DYViewerParameterDiagnostics.inc.h"
#include "DYViewerControlsDiagnostics.inc.h"
#include "DYCanvasToolsDiagnostics.inc.h"
[gpu release];
} @catch(NSException *exception) {
run.record(@"diagnostic-exception",false,@{@"exception":exception.name?:@"unknown",@"message":exception.reason?:@"unknown"});