~james/remy

fix(guest): release loaded buffers when execution fails

commit
dba8e6d26f3995a03c1c6766135e705d3045ebec browse tree
parent
5fcf9d2c41a83fa9834748fbfbcaf54837c9c7b3
author
james <j@cpl0.zip>
signature
Verified ~james signed with a key registered by ~james
date
2026-10-30 12:00 UTC

1 files changed, +63 −42

guest/Remy.HC modified

@@ -22,23 +22,30 @@ I64 selected;
2222 U0 Verify()
2323 {
2424 I64 i,j,size,total=0;
25- U8 *code,path[64];
26- U64 *rows;
27- for (i=0;i<3;i++) {
28- StrPrint(path,"C:/%s.BIN",names[i]);
29- code=FileRead(path,&size);
30- if (!code) throw('Code');
31- "%-6s %d bytes ",names[i],size;
32- StrPrint(path,"C:/%s.DAT",names[i]);
33- rows=FileRead(path,&size);
34- if (!rows || size!=16384) throw('Vectors');
35- for (j=0;j<size/32;j++) {
36- if (Pixel(code,rows[4*j],rows[4*j+1],rows[4*j+2])!=rows[4*j+3]) {
37- throw('Mismatch');
25+ U8 *code=NULL,path[64];
26+ U64 *rows=NULL;
27+ try {
28+ for (i=0;i<3;i++) {
29+ StrPrint(path,"C:/%s.BIN",names[i]);
30+ code=FileRead(path,&size);
31+ if (!code) throw('Code');
32+ "%-6s %d bytes ",names[i],size;
33+ StrPrint(path,"C:/%s.DAT",names[i]);
34+ rows=FileRead(path,&size);
35+ if (!rows || size!=16384) throw('Vectors');
36+ for (j=0;j<size/32;j++) {
37+ if (Pixel(code,rows[4*j],rows[4*j+1],rows[4*j+2])!=rows[4*j+3]) {
38+ throw('Mismatch');
39+ }
40+ total++;
3841 }
39- total++;
42+ "%d comparisons passed\n",size/32;
43+ Free(rows);
44+ rows=NULL;
45+ Free(code);
46+ code=NULL;
4047 }
41- "%d comparisons passed\n",size/32;
48+ } catch {
4249 Free(rows);
4350 Free(code);
4451 }
@@ -54,40 +61,54 @@ U0 Draw(CTask *,CDC *dc)
5461 GrPrint(dc,80,416,"%s",program);
5562 }
5663
64+U0 Release(Bool restore)
65+{
66+ Fs->draw_it=NULL;
67+ if (restore) SettingsPop;
68+ DCDel(image);
69+ image=NULL;
70+ Free(shader);
71+ shader=NULL;
72+ Free(program);
73+ program=NULL;
74+}
75+
5776 U0 Show(I64 which=0)
5877 {
5978 I64 x,y,dy,t=0;
6079 U8 color,path[64];
80+ Bool restore=FALSE;
6181 if (!(0<=which<3)) return;
62- selected=which;
63- StrPrint(path,"C:/%s.BIN",names[which]);
64- shader=FileRead(path);
65- if (!shader) throw('Code');
66- StrPrint(path,"C:/%s.TXT",names[which]);
67- program=FileRead(path);
68- if (!program) throw('Source');
69- image=DCNew(480,336);
70- SettingsPush;
71- AutoComplete(OFF);
72- WinMax;
73- DocClear;
74- Fs->draw_it=&Draw;
75- while (!ScanChar) {
76- for (y=0;y<112;y++) {
77- for (x=0;x<160;x++) {
78- color=Pixel(shader,x,y,t)&15;
79- for (dy=0;dy<3;dy++)
80- MemSet(image->body+(3*y+dy)*480+3*x,color,3);
82+ try {
83+ selected=which;
84+ StrPrint(path,"C:/%s.BIN",names[which]);
85+ shader=FileRead(path);
86+ if (!shader) throw('Code');
87+ StrPrint(path,"C:/%s.TXT",names[which]);
88+ program=FileRead(path);
89+ if (!program) throw('Source');
90+ image=DCNew(480,336);
91+ SettingsPush;
92+ restore=TRUE;
93+ AutoComplete(OFF);
94+ WinMax;
95+ DocClear;
96+ Fs->draw_it=&Draw;
97+ while (!ScanChar) {
98+ for (y=0;y<112;y++) {
99+ for (x=0;x<160;x++) {
100+ color=Pixel(shader,x,y,t)&15;
101+ for (dy=0;dy<3;dy++)
102+ MemSet(image->body+(3*y+dy)*480+3*x,color,3);
103+ }
81104 }
105+ t+=2;
106+ Refresh;
107+ Sleep(20);
82108 }
83- t+=2;
84- Refresh;
85- Sleep(20);
109+ } catch {
110+ Release(restore);
86111 }
87- Fs->draw_it=NULL;
88- SettingsPop;
89- DCDel(image);
90- Free(shader);
91- Free(program);
112+ Release(restore);
92113 DocClear;
93114 }