fix mac os memleak, maybe fix stringisutf8 idk

This commit is contained in:
IoI_xD 2026-04-14 19:38:52 -07:00
commit 4d7b33741f
3 changed files with 40 additions and 48 deletions

View file

@ -18,13 +18,13 @@ typedef struct {
} type; } type;
union { union {
struct { struct {
MwPoint* points; MwPoint* points;
int points_count; int points_count;
MwLLColor color; struct _MwLLCommonColor color;
} poly; } poly;
struct { struct {
MwPoint* points; MwPoint* points;
MwLLColor color; struct _MwLLCommonColor color;
} lines; } lines;
struct { struct {
MwRect rect; MwRect rect;
@ -107,7 +107,7 @@ typedef struct {
MwBool _child; MwBool _child;
@public @public
draw_command** commands; draw_command* commands;
} }
- (void)destroy; - (void)destroy;

View file

@ -99,21 +99,21 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
[super drawRect:dirtyRect]; [super drawRect:dirtyRect];
for(i = 0; i < arrlen(self->commands); i++) { for(i = 0; i < arrlen(self->commands); i++) {
draw_command* cmd = self->commands[i]; draw_command cmd = self->commands[i];
switch(cmd->type) { switch(cmd.type) {
case COCOA_DRAW_COMMAND_POLY: { case COCOA_DRAW_COMMAND_POLY: {
int n; int n;
NSBezierPath* path = [NSBezierPath bezierPath]; NSBezierPath* path = [NSBezierPath bezierPath];
NSColor* nscolor = NSColor* nscolor =
[NSColor colorWithCalibratedRed:cmd->poly.color->common.red / 255. [NSColor colorWithCalibratedRed:cmd.poly.color.red / 255.
green:cmd->poly.color->common.green / 255. green:cmd.poly.color.green / 255.
blue:cmd->poly.color->common.blue / 255. blue:cmd.poly.color.blue / 255.
alpha:1.0]; alpha:1.0];
[nscolor setFill]; [nscolor setFill];
for(n = 0; n < cmd->poly.points_count; n++) { for(n = 0; n < cmd.poly.points_count; n++) {
NSPoint p = localPointFlip(NSMakePoint(cmd->poly.points[n].x, cmd->poly.points[n].y), self); NSPoint p = localPointFlip(NSMakePoint(cmd.poly.points[n].x, cmd.poly.points[n].y), self);
if(n == 0) { if(n == 0) {
[path moveToPoint:p]; [path moveToPoint:p];
} else { } else {
@ -124,10 +124,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
[path closePath]; [path closePath];
[path fill]; [path fill];
free(cmd->poly.points); free(cmd.poly.points);
MwLLFreeColor(cmd->poly.color);
free(cmd);
} break; } break;
case COCOA_DRAW_COMMAND_LINES: { case COCOA_DRAW_COMMAND_LINES: {
@ -135,14 +132,14 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
NSBezierPath* path = [NSBezierPath bezierPath]; NSBezierPath* path = [NSBezierPath bezierPath];
NSColor* nscolor = NSColor* nscolor =
[NSColor colorWithCalibratedRed:cmd->lines.color->common.red / 255. [NSColor colorWithCalibratedRed:cmd.lines.color.red / 255.
green:cmd->lines.color->common.green / 255. green:cmd.lines.color.green / 255.
blue:cmd->lines.color->common.blue / 255. blue:cmd.lines.color.blue / 255.
alpha:1.0]; alpha:1.0];
[nscolor setFill]; [nscolor setFill];
for(n = 0; n < 2; n++) { for(n = 0; n < 2; n++) {
NSPoint p = localPointFlip(NSMakePoint(cmd->lines.points[n].x, cmd->lines.points[n].y), self); NSPoint p = localPointFlip(NSMakePoint(cmd.lines.points[n].x, cmd.lines.points[n].y), self);
if(n == 0) { if(n == 0) {
[path moveToPoint:p]; [path moveToPoint:p];
} else { } else {
@ -153,19 +150,16 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
[path closePath]; [path closePath];
[path stroke]; [path stroke];
free(cmd->lines.points); free(cmd.lines.points);
MwLLFreeColor(cmd->lines.color);
free(cmd);
} break; } break;
case COCOA_DRAW_COMMAND_PIXMAP: { case COCOA_DRAW_COMMAND_PIXMAP: {
[cmd->pixmap.pixmap->cocoa.real->image [cmd.pixmap.pixmap->cocoa.real->image
drawInRect:localRectFlip(NSMakeRect(cmd->pixmap.rect.x, cmd->pixmap.rect.y, cmd->pixmap.rect.width, cmd->pixmap.rect.height), self) drawInRect:localRectFlip(NSMakeRect(cmd.pixmap.rect.x, cmd.pixmap.rect.y, cmd.pixmap.rect.width, cmd.pixmap.rect.height), self)
fromRect:NSZeroRect fromRect:NSZeroRect
operation:NSCompositeSourceOver operation:NSCompositeSourceOver
fraction:1.0]; fraction:1.0];
MwLLDestroyPixmap(cmd->pixmap.pixmap); MwLLDestroyPixmap(cmd.pixmap.pixmap);
free(cmd);
} break; } break;
} }
} }
@ -742,32 +736,28 @@ static void MwLLEndDrawImpl(MwLL handle) {
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count,
MwLLColor color) { MwLLColor color) {
draw_command* poly = malloc(sizeof(draw_command)); draw_command poly;
poly->type = COCOA_DRAW_COMMAND_POLY; poly.type = COCOA_DRAW_COMMAND_POLY;
poly->poly.color = MwLLAllocColor(handle, color->common.red, color->common.green, color->common.blue); poly.poly.color = color->common;
poly->poly.points_count = points_count; poly.poly.points_count = points_count;
poly->poly.points = malloc(sizeof(MwPoint) * points_count); poly.poly.points = malloc(sizeof(MwPoint) * points_count);
memcpy(poly->poly.points, points, sizeof(MwPoint) * points_count); memcpy(poly.poly.points, points, sizeof(MwPoint) * points_count);
arrpush(handle->cocoa.real->view->commands, poly); arrpush(handle->cocoa.real->view->commands, poly);
// [handle->cocoa.real->view setNeedsDisplay:MwTRUE];
// [handle->cocoa.real->view displayRect:[handle->cocoa.real->window frame]];
} }
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
draw_command* lines = malloc(sizeof(draw_command)); draw_command lines;
lines->type = COCOA_DRAW_COMMAND_LINES; lines.type = COCOA_DRAW_COMMAND_LINES;
lines->lines.color = MwLLAllocColor(handle, color->common.red, color->common.green, color->common.blue); lines.lines.color = color->common;
lines->lines.points = malloc(sizeof(MwPoint) * 2); lines.lines.points = malloc(sizeof(MwPoint) * 2);
memcpy(lines->lines.points, points, sizeof(MwPoint) * 2); memcpy(lines.lines.points, points, sizeof(MwPoint) * 2);
arrpush(handle->cocoa.real->view->commands, lines); arrpush(handle->cocoa.real->view->commands, lines);
// [handle->cocoa.real->view setNeedsDisplay:MwTRUE];
} }
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) { static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
@ -918,18 +908,20 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) {
} }
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
free(pixmap->common.raw);
[pixmap->cocoa.real destroy]; [pixmap->cocoa.real destroy];
[pixmap->cocoa.real release]; [pixmap->cocoa.real release];
free(pixmap); free(pixmap);
} }
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
draw_command* pix = malloc(sizeof(draw_command)); draw_command pix;
pix->type = COCOA_DRAW_COMMAND_PIXMAP; pix.type = COCOA_DRAW_COMMAND_PIXMAP;
pix.pixmap.rect = *rect;
pix->pixmap.rect = *rect;
/* copy the pixmap into a new object that we'll free later */ /* copy the pixmap into a new object that we'll free later */
pix->pixmap.pixmap = MwLLCreatePixmap(handle, pixmap->common.raw, pixmap->common.width, pixmap->common.height); pix.pixmap.pixmap = MwLLCreatePixmap(handle, pixmap->common.raw, pixmap->common.width, pixmap->common.height);
arrpush(handle->cocoa.real->view->commands, pix); arrpush(handle->cocoa.real->view->commands, pix);
// [handle->cocoa.real->view setNeedsDisplay:MwTRUE]; // [handle->cocoa.real->view setNeedsDisplay:MwTRUE];

View file

@ -51,7 +51,7 @@ void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) {
}; };
MWDECL MwBool MwStringIsKeyUTF8(MwU32 key) { MWDECL MwBool MwStringIsKeyUTF8(MwU32 key) {
unsigned char bytes[sizeof(MwU32)]; unsigned char bytes[sizeof(MwU32) * 16];
int i; int i;
memcpy(bytes, &key, sizeof(MwU32)); memcpy(bytes, &key, sizeof(MwU32));