Commit Graph

17 Commits

Author SHA1 Message Date
Simon Anciaux 0e2b8d0df8 A user reported on the handmade network discord an issue where when you change the font size (e.g. ctrl + scroll up/down) 4coder was crashing. They were using the D3D11 renderer.
The crash is caused by dereferencing a invalid pointer to a texture. The D3D11 renderer as a arbitrary limit of 32 textures (there is normally no reason to have more than 2 or 3 textures in 4coder) because it needs to keep track of a few pointer in its state, while OpenGL doesn't (it just uses the id returned by `glGenTexture`). The code that recreate the texture atlas when changing the font size, never frees the previous texture, so both DirectX and OpenGL are leaking texture.

So this fix just frees the previous texture after 4coder successfully creates a new one. If for some reason the new texture can't be created, we continue using the last one. This is better than crashing as we can still use 4coder, but since we can't change font size anymore the editor might be stuck with a uncomfortable font size.

Unfortunately 4coder doesn't expose a way to delete texture outside the platform layer, and the font size code is not in the platform layer. So I had to expose a `free texture` function, which lead me to understand how 4coder generates API in the `generated` folder.

I updated the README to keep that information somewhere since it's not clear from the get go. The basic idea is that there are a few files that you can compile as a small standalone program and run to generate the files. For the graphics api, you need to compile `4ed_graphics_api.cpp`.

I took some time to also modify a little the generator so that the generated file contains the name of the file that generated them, and added a bit of indentation to make the file a bit more readable (even if we're not supposed to modify them).
2025-07-07 13:11:48 -07:00
Simon Anciaux c194053b83 4ed_generate_keycodes.cpp adds a comment at the top of the file it generate to specify which file generated it. Added proper indentation in the generated file. Note that this executable needs to be manually ran. The build system doesn't run it.
win32_keycode_init only initialize 30 KeyCode_Ex values (0 to 29) as the code generating the enum only generates that amount (explicitly loops from 0 to < 30).
2025-07-07 13:09:34 -07:00
Simon Anciaux 33c3428796 Clipboard fix
Fixed duplicated entries in 4coder internal clipboard (Fix from VDK on the 4coder discord).
Removed the unnecessary loop that was there to try to fix the clipboard missing entries (which was fixed previously by removing the `next_clipboard_is_self` variable).
2025-07-07 13:07:35 -07:00
Simon Anciaux dfce9bf369 Fix wrong initialization of keycode lookup table
Up until now, several keys were assigned the same key value because the `keycode_lookup_table` array wasn't properly initialized. The values at the end of the array were all set to `KeyCode_Ex0 + 1` which is 112. This would cause several key to be treated as the same key.

In my case the key next to the left shift key ( `<` and `>` on AZERTY) was getting the same value as the `Right Windows key`. But I suppose that the left and right windows key would get the same value too (I can't check this as I have only 1 windows key on my keyboard).

This fix just properly initialize the array. I also fixed a typo in a function name: `keycode_physical_translaion_is_wrong` => `keycode_physical_translation_is_wrong`.
2025-07-07 13:06:29 -07:00
Simon Anciaux f3dc516704 Disable DXGI monitoring the message queue for Alt+Enter fullscreen switch. Switching that way instead of calling toggle_fullscreen, causes issue when trying to Alt+Tab. Also users might want to use Alt+Enter for other things.
Changed how DXGI factory is handled. I retrieve the one associated with the current DXGI device and adapter instead of creating a new one.
Fixed missing new line in the log at 1 location.
2025-07-07 13:05:28 -07:00
Simon Anciaux dadb7dc49a Fixed crashing when 4coder tries to render more vertex than the vertex buffer reserved. We create a new buffer to accommodate the required size, and if that fails, we skip rendering the current vertex group. 2025-07-07 13:04:14 -07:00
Simon Anciaux 84da2da350 Changed `true` to `GL_TRUE` for `WGL_DOUBLE_BUFFER_ARB` to use OpenGL wording. 2025-07-07 13:03:52 -07:00
Simon Anciaux cbbd83affc Commented the DirectX 11 define to default to OpenGL. 2025-07-07 13:03:44 -07:00
Simon Anciaux c81d9b4e97 Renamed files from direcx to dx11. 2025-07-07 13:03:34 -07:00
Simon Anciaux d0a18fcdb7 Renamed "directx" to dx11 in several variable names, types and defines.
Added date to NOTEs and TODOs.
Tried to make log strings more useful, even if I don't know how you display things log with log_os.
2025-07-07 13:03:26 -07:00
Simon Anciaux 7ce0a7d698 code/platform_win32/4ed_directx_render.cpp: Reuse freed textures. Rename variables so that texture handle are always named texid. 2025-07-07 13:03:19 -07:00
Simon Anciaux b651847ba3 4ed_directx_render.cpp: Initialize textures to zero to avoid having random pixel values that changes the result of linear sampling on the edge of characters. 2025-07-07 13:03:10 -07:00
Simon Anciaux e4b4e5c943 code/platform_win32/4ed_directx_render.cpp: Fixed the way texture array are updated. Note that the font provider rectangle packer contains a bug, and it will never produce several texture slice, it will only grow the texture on y to accommodate for more characters.
code/platform_win32/win32_opengl.cpp: Enabled double buffering to fix graphical glitches on AMD cards.
2025-07-07 13:02:52 -07:00
Simon Anciaux 911df4ce05 code/bin/4ed_build.cpp: Removed OpenGL.lib. It's added with #pragma comment in win32_opengl.cpp so that we don't need to do special things to keep OpenGL and DirectX both working.
code/platform_win32/win32_4ed.cpp:
- Modification to be able to choose between OpenGL and DirectX. You choose between the two by defining WIN32_DIRECTX macro. If you don't define it it uses OpenGL.
- Note that win32_gl_create_window and other part of the file that depend on OpenGL or DirectX have been moved to win32_opengl.cpp and win32_directx.cpp.
- Fixed os_popup_error using the title as the message and the message as the title.

code/platform_win32/win32_opengl.cpp: Contains previous code that was in win32_4ed.cpp.

code/platform_win32/win32_directx.cpp: Code for creating a DirectX window and context.

code/platform_win32/4ed_directx_render.cpp: Imlementation of the 4coder renderer using DirectX.
2025-07-07 13:02:42 -07:00
PS 80b780278a Removed custom/audio 2024-02-10 14:25:13 -08:00
Jack Punter e3cbab907b Remove win32 clipboard flag which ocasionally results in mis-paste from the system clipboard 2023-11-01 21:24:36 +00:00
Jack Punter 0e47ccd2ce Add 'code/' from commit '1459ef7cbce753b056ea148b29c9dc3f8a721261'
git-subtree-dir: code
git-subtree-mainline: cf6a50363e
git-subtree-split: 1459ef7cbc
2022-11-18 13:37:07 +00:00