AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

92

TVDispose: Don't use TVClear, it redraws

We are likely in a window teardown where we shouldn't be drawing.
 
Also TVClear was leaving the first of each slab allocated.

jcs made amendment 92 20 days ago
--- textview.c Tue Nov 3 15:33:49 2026 +++ textview.c Thu Nov 5 20:56:55 2026 @@ -19,6 +19,8 @@ #include <string.h> #include "textview.h" +void TVDisposeSlabs(Handle slabh); + TVHandle TVNew(Rect *view, Rect *padding) { @@ -395,19 +397,37 @@ TVClear(TVHandle tvh) } void +TVDisposeSlabs(Handle slabh) +{ + Handle nexth; + + while (slabh != NULL) { + nexth = ((struct TVSlab *)*slabh)->next_slab; + DisposeHandle(slabh); + slabh = nexth; + } +} + +void TVDispose(TVHandle tvh) { struct TVRec *tv; + short n; - /* this will free all but the first slabs */ - TVClear(tvh); - - tv = TVLock(tvh); + /* do no drawing in here */ - DisposeHandle(tv->first_style_slab); - DisposeHandle(tv->first_chunk_slab); - DisposeHandle(tv->first_text_slab); - DisposeHandle(tv->line_groups[0]); + HLock(tvh); + tv = *tvh; + + TVDisposeSlabs(tv->first_style_slab); + TVDisposeSlabs(tv->first_chunk_slab); + TVDisposeSlabs(tv->first_text_slab); + + for (n = 0; n < sizeof(tv->line_groups) / sizeof(tv->line_groups[0]); + n++) { + if (tv->line_groups[n] != NULL) + DisposeHandle(tv->line_groups[n]); + } #ifdef USE_CANVAS ClosePort(tv->canvas);