From 94ee03800db06330e129ba02b1125696fd53b823 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 21 Mar 2026 10:10:24 +0100 Subject: [PATCH] Basic tests and trying to fix address sanitizer errors --- build.sh | 3 ++- src/plugin_tests.cpp | 16 ++++++++++++++++ src/render_font.cpp | 2 +- src/render_opengl.cpp | 22 ++++++++++------------ src/text_editor.cpp | 26 +++++++++++++++++--------- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/build.sh b/build.sh index 31220d9..9a973c8 100755 --- a/build.sh +++ b/build.sh @@ -13,7 +13,8 @@ if [ ! -e "src/external/SDL" ]; then git clone https://github.com/libsdl-org/SDL.git cd SDL git checkout release-3.2.30 - # cmake -S . -B build_linux -DCMAKE_BUILD_TYPE=Release -DSDL_PIPEWIRE=OFF + # We need older version of SDL3 because there is a bug on wayland that + # doubles click events and it's kind of unusable cmake -S . -B build_linux -DSDL_PIPEWIRE=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr cd build_linux sudo make -j16 install diff --git a/src/plugin_tests.cpp b/src/plugin_tests.cpp index 3cf7fc0..75bdda0 100644 --- a/src/plugin_tests.cpp +++ b/src/plugin_tests.cpp @@ -1,3 +1,4 @@ +#if PLUGIN_TESTS bool Testing = true; void Wait(mco_coro *co) { @@ -37,4 +38,19 @@ void CO_FirstTest(mco_coro *co) { {Event ev = {};ev.kind = EVENT_TEXT_INPUT; ev.xwindow = 1412; ev.ywindow = 1032; ev.xmouse = 1234; ev.ymouse = 594; ev.text = "f"; Add(&EventPlayback, ev);} Wait(co); + String16 result = uR"FOO( + + + + + + +Memes and stuff)FOO"; + BSet set = GetBSet(PrimaryWindowID); + Assert(AreEqual(result, GetString(set.buffer))); + + void CMD_QuitWithoutSaving(); + CMD_QuitWithoutSaving(); + } RegisterCoroutineCommand(CO_FirstTest, "", "Basic tests"); +#endif diff --git a/src/render_font.cpp b/src/render_font.cpp index 4f3513d..51b3d34 100644 --- a/src/render_font.cpp +++ b/src/render_font.cpp @@ -119,7 +119,7 @@ Font CreateFont(Atlas *atlas, int32_t size, String path) { } stbtt_fontinfo stb_font; - int success = stbtt_InitFont(&stb_font, (const unsigned char *)file.data, 0); + int success = stbtt_InitFont(&stb_font, (const unsigned char *)file.data, 0); if (!success) { return result; } diff --git a/src/render_opengl.cpp b/src/render_opengl.cpp index 4b2c516..3c131d7 100644 --- a/src/render_opengl.cpp +++ b/src/render_opengl.cpp @@ -18,22 +18,20 @@ struct VertexList2D { struct Shader { GLuint program; // linked program (vertex+fragment) - GLint uni_invHalf; // uniform location for inv half-screen size - GLint uni_texture; // sampler location + GLint uni_invHalf; // uniform location for inv half-screen size + GLint uni_texture; // sampler location }; VertexList2D Vertices; -int64_t TotalVertexCount; +int64_t TotalVertexCount; unsigned VBO, VAO; -Shader Shader2D; +Shader Shader2D; BlockArena RenderArena; -Rect2 CurrentScissor; +Rect2 CurrentScissor; Font PrimaryFont; -Font SecondaryFont; -// ---------- shaders (ES3 / WebGL2) ---------- static const char *glsl_vshader_es3 = R"==(#version 300 es precision highp float; @@ -82,7 +80,6 @@ void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLs } } -// ---------- helper: compile/link ---------- static GLuint CompileShaderSrc(GLenum kind, const char *src) { GLuint s = glCreateShader(kind); glShaderSource(s, 1, &src, NULL); @@ -137,7 +134,6 @@ Shader CreateShaderES3(const char *vsrc, const char *fsrc) { return out; } -// ---------- InitRender for ES3 ---------- void InitRender() { #if !OS_WASM glDebugMessageCallback(&GLDebugCallback, NULL); @@ -185,7 +181,6 @@ void BeginFrameRender(float wx, float wy) { CurrentScissor = Rect0Size(wx, wy); } -// ---------- EndFrameRender for ES3 ---------- void EndFrameRender(float wx, float wy, Color color) { ProfileFunction(); glEnable(GL_BLEND); @@ -391,6 +386,9 @@ void ReloadFont(String path, U32 size) { Scratch scratch; Atlas atlas = CreateAtlas(scratch, {2048, 2048}); PrimaryFont = CreateFont(&atlas, (uint32_t)ClampBottom(2u, (U32)size), path); - SecondaryFont = CreateFont(&atlas, 12, path); - SecondaryFont.texture_id = PrimaryFont.texture_id = UploadAtlas(&atlas); + PrimaryFont.texture_id = UploadAtlas(&atlas); } + +void CleanupRender() { + Dealloc(&PrimaryFont.glyphs); +} \ No newline at end of file diff --git a/src/text_editor.cpp b/src/text_editor.cpp index 54ff0a5..1e44dab 100644 --- a/src/text_editor.cpp +++ b/src/text_editor.cpp @@ -1,6 +1,7 @@ /* +- [ ] Switch fully to VSCode keybindings and learn to live with it - [x] list_functions.sh and rg in general in the color mode is prinitng differently from terminal as well as output is truncated! -- [ ] Syntax for executing commands from root of project +- [ ] Syntax for executing commands from root of project, or maybe commands should be executed from root of the CurrentDirectory and there should be a cd command instead of OpenProject - [ ] Fuzzy search over executed command ouput - [ ] When inserting parenthesis and selection is there, put the parens on both sides? - [ ] KillProcess in console !!! - should also kill all the children ........... @@ -13,6 +14,10 @@ - [x] BRO, the caret teleports on linux when I press the arrow for too long - [ ] Report SDL newest vs SDL previous version on wayland +- [ ] Ctrl+Shift+ArrowDown at the end of buffer, doesn't capture characters on last line without new line +- [ ] Remove -lbacktrace and add my backtrace library thing +- [ ] Refactor build.sh to accept commands and remove build_web.sh + - [ ] Cleanups - [ ] How to enable framerate to be unlimited and not break scrolling? - [x] When dragging a file into the editor, would be nice if the file opened in the window user dropped the file into. Not the active window. @@ -91,6 +96,7 @@ #define PLUGIN_REMEDYBG OS_WINDOWS #define PLUGIN_FILE_COMMANDS 1 #define PLUGIN_WORD_COMPLETE 1 +#define PLUGIN_TESTS 1 #include "plugin_directory_navigation.h" #include "plugin_search_window.h" @@ -153,17 +159,16 @@ void SetMouseCursor(SDL_SystemCursor id) { } } #else +SDL_Cursor *SDL_MouseCursor; +SDL_SystemCursor SDL_MouseCursorLastID; void SetMouseCursor(SDL_SystemCursor id) { - static SDL_Cursor *SDL_MouseCursor; - static SDL_SystemCursor last_id; - - if (SDL_MouseCursor == NULL || last_id != id) { + if (SDL_MouseCursor == NULL || SDL_MouseCursorLastID != id) { if (SDL_MouseCursor != NULL) { SDL_DestroyCursor(SDL_MouseCursor); } SDL_MouseCursor = SDL_CreateSystemCursor(id); SDL_SetCursor(SDL_MouseCursor); - last_id = id; + SDL_MouseCursorLastID = id; } } #endif @@ -216,9 +221,6 @@ void SetMouseCursor(Event event) { } void CMD_QuitWithoutSaving() { -#if PLUGIN_REMEDYBG - QuitDebugger(); -#endif AppIsRunning = false; } RegisterCommand(CMD_QuitWithoutSaving, "", "Self explanatory"); @@ -1136,6 +1138,12 @@ int main(int argc, char **argv, char **envp) } #endif +#if PLUGIN_REMEDYBG + QuitDebugger(); +#endif + CleanupRender(); + + SDL_DestroyCursor(SDL_MouseCursor); SDL_DestroyWindow(SDLWindow); SDL_Quit();