Fix memory corruption

This commit is contained in:
Krzosa Karol
2024-07-28 20:49:40 +02:00
parent 77a6cc5e53
commit 12b459507a
5 changed files with 19 additions and 15 deletions

View File

@@ -1034,8 +1034,11 @@ inline TempArena GetScratch(Arena *c1 = NULL, Arena *c2 = NULL) {
struct Scratch {
TempArena checkpoint;
Scratch() { this->checkpoint = GetScratch(); }
Scratch(Arena *conflict) { this->checkpoint = GetScratch(conflict); }
Scratch(Arena *c1, Arena *c2) { this->checkpoint = GetScratch(c1, c2); }
Scratch(Allocator conflict) { this->checkpoint = GetScratch((Arena *)conflict.object); }
Scratch(Allocator c1, Allocator c2) { this->checkpoint = GetScratch((Arena *)c1.object, (Arena *)c2.object); }
~Scratch() { EndTemp(checkpoint); }
operator Arena *() { return checkpoint.arena; }
operator Allocator() { return *checkpoint.arena; }

View File

@@ -270,7 +270,7 @@ String GetExePath(Allocator allocator) {
}
String GetExeDir(Allocator allocator) {
Scratch scratch;
Scratch scratch((Arena *)allocator.object);
String path = GetExePath(scratch);
path = ChopLastSlash(path);
path = Copy(allocator, path);

View File

@@ -217,20 +217,20 @@ void MergeCarets(View *view, Range *mouse_selection_anchor) {
Swap(&view->carets[first_caret_index], &view->carets[0]);
}
String DebugViewList() {
Scratch scratch;
String DebugViewList(Allocator allocator) {
Scratch scratch((Arena *)allocator.object);
Array<String> strings = {scratch};
For(Views) {
Buffer *buffer = GetBuffer(it.active_buffer);
String string = Format(scratch, "view = %lld buffer = %lld name = %.*s", (long long)it.id.id, (long long)buffer->id.id, FmtString(buffer->name));
Add(&strings, string);
}
String result = Merge(scratch, strings, "\n");
String result = Merge(allocator, strings, "\n");
return result;
}
String DebugWindowList() {
Scratch scratch;
String DebugWindowList(Allocator allocator) {
Scratch scratch((Arena *)allocator.object);
Array<String> strings = {scratch};
For(Windows) {
View *view = GetActiveView(&it);
@@ -244,7 +244,7 @@ String DebugWindowList() {
Add(&strings, child_string);
}
}
String result = Merge(scratch, strings, "\n");
String result = Merge(allocator, strings, "\n");
return result;
}
@@ -264,11 +264,11 @@ void ReplaceDebugData() {
String16 string = ToString16(scratch, s);
ReplaceText(buffer, GetRange(*buffer), string);
// String view_list = DebugViewList();
// Append(buffer, ToString16(scratch, view_list));
String view_list = DebugViewList(scratch);
Append(buffer, ToString16(scratch, view_list));
// String window_list = DebugWindowList();
// Append(buffer, ToString16(scratch, window_list));
String window_list = DebugWindowList(scratch);
Append(buffer, ToString16(scratch, window_list));
}
void ReplaceInfobarData() {

View File

@@ -10,8 +10,9 @@
- open "asd/asd/asd/asd"
- word completion
- Colored strings
- open project files in folder and only show open views in Ctrl+P
- Set scroll centered
- file lister
- Remove view children, replace with view history
- font cache and on demand unicode loads

View File

@@ -120,14 +120,14 @@ void LayoutWindows() {
int i = 0;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.5));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, FontCharSpacing);
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, (Int)(10.f * DPIScale));
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 1;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, FontCharSpacing);
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, (Int)(10.f * DPIScale));
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{