Skip to content

Migrate to SDL3#2882

Merged
AaronVanGeffen merged 17 commits intoOpenLoco:masterfrom
ZehMatt:sdl3
Mar 7, 2026
Merged

Migrate to SDL3#2882
AaronVanGeffen merged 17 commits intoOpenLoco:masterfrom
ZehMatt:sdl3

Conversation

@ZehMatt
Copy link
Copy Markdown
Contributor

@ZehMatt ZehMatt commented Feb 3, 2025

I wanted to see what sort of pain this would be, it was okay'ish but by updating the vcpkg version it also updated OpenAL which now compiles libfmt by adding the source files directly and that causes a conflict in linking on my end so I don't even know if my changes work or not. I've created a new issue on the OpenAL repo and hopefully it will get resolved, I might solve this myself but then we would have to either use a port overlay or fetchcontent from the fork.

Edit: As for the new SDL3 API, I appreciate some changes and I dislike some others but I think generally speaking SDL3 is a good upgrade.

@duncanspumpkin
Copy link
Copy Markdown
Contributor

@ZehMatt are you able to resurrect this? Would be useful now as some linux distros have dropped sdl2.

@carlo-bramini

This comment was marked as resolved.

@ZehMatt
Copy link
Copy Markdown
Contributor Author

ZehMatt commented Jan 30, 2026

Done, we need to update the images to have SDL3 pre-installed.

@duncanspumpkin
Copy link
Copy Markdown
Contributor

Done, we need to update the images to have SDL3 pre-installed.

I'm noticing that sdl3 isn't building on linux vcpkg so I've tried updating vcpkg to target the latest version.

@ZehMatt ZehMatt force-pushed the sdl3 branch 3 times, most recently from 006e6ba to e87094b Compare February 2, 2026 21:25
@ZehMatt ZehMatt marked this pull request as ready for review February 2, 2026 21:27
@duncanspumpkin
Copy link
Copy Markdown
Contributor

OpenLoco/openloco-docker-build#18

Copy link
Copy Markdown
Member

@AaronVanGeffen AaronVanGeffen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch crashes immediately on open for me:

[INF] OpenLoco, v26.01-18 (35d1a9f6 on sdl3)
[INF] macOS (AArch64)
Process 20407 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4)
    frame #0: 0x000000010008f8c8 OpenLoco`OpenLoco::Gfx::SoftwareDrawingEngine::resize(int, int) + 168
OpenLoco`OpenLoco::Gfx::SoftwareDrawingEngine::resize:
->  0x10008f8c8 <+168>: ldr    w2, [x22, #0x4]
    0x10008f8cc <+172>: mov    x0, x20
    0x10008f8d0 <+176>: mov    x1, x21
    0x10008f8d4 <+180>: bl     0x1002350b4    ; symbol stub for: SDL_CreateSurface
Target 0: (OpenLoco) stopped.

It was puzzling to me, as it already seemed to be programmed quite defensibly. Well, as it turns out, not defensibly enough. I added:

        const auto* wndSurface = SDL_GetWindowSurface(_window);
+       if (wndSurface == nullptr)
+       {
+           Logging::error("SDL_GetWindowSurface (_window) failed: {}", SDL_GetError());
+           return;
+       }

And got the error message:

[ERR] SDL_GetWindowSurface (_window) failed: Window framebuffer support not available

Upon which another error popped up further down the line:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001000904bc OpenLoco`OpenLoco::Gfx::SoftwareDrawingEngine::present() + 24
OpenLoco`OpenLoco::Gfx::SoftwareDrawingEngine::present:
->  0x1000904bc <+24>: ldrb   w8, [x0]
    0x1000904c0 <+28>: tbz    w8, #0x1, 0x1000904d0 ; <+44>
    0x1000904c4 <+32>: bl     0x1002351ec    ; symbol stub for: SDL_LockSurface
    0x1000904c8 <+36>: cbz    w0, 0x1000905c0 ; <+284>
Target 0: (OpenLoco) stopped.

Which kind of makes sense, if there is no window to present. Why this is happening at all is unclear to me, still, though. I can try to investigate some more later, on Linux as well.

@AaronVanGeffen
Copy link
Copy Markdown
Member

Same issue on Arch Linux:

$ lldb ./OpenLoco
(lldb) target create "./OpenLoco"
Current executable set to '/home/aaron/Projects/OpenLoco/OpenLoco/build/posix/Debug/OpenLoco' (x86_64).
(lldb) run
Process 24151 launched: '/home/aaron/Projects/OpenLoco/OpenLoco/build/posix/Debug/OpenLoco' (x86_64)
OpenLoco, v26.01-19 (970940f0 on sdl3, DEBUG)
Linux (x86-64)
SDL_GetWindowSurface (_window) failed: Window framebuffer support not available
OpenLoco: /home/aaron/Projects/OpenLoco/OpenLoco/src/OpenLoco/src/ViewportManager.cpp:68: OpenLoco::Ui::Viewport* OpenLoco::Ui::ViewportManager::initViewport(OpenLoco::Ui::Point, OpenLoco::Ui::Size, OpenLoco::ZoomLevel): Assertion `size.width != 0' failed.
Process 24151 stopped
* thread #1, name = 'OpenLoco', stop reason = signal SIGABRT
    frame #0: 0x00007ffff72a7a2c libc.so.6`__pthread_kill_implementation(threadid=<unavailable>, signo=6, no_tid=<unavailable>) at pthread_kill.c:44:76

Slightly different backtrace though:

(lldb) bt
error: OpenLoco 0x019a07bc: DW_TAG_member '_M_local_buf' refers to type 0x00000000019c0986 which extends beyond the bounds of 0x019a07b2
* thread #1, name = 'OpenLoco', stop reason = signal SIGABRT
  * frame #0: 0x00007ffff72a7a2c libc.so.6`__pthread_kill_implementation(threadid=<unavailable>, signo=6, no_tid=<unavailable>) at pthread_kill.c:44:76
    frame #1: 0x00007ffff724d1a0 libc.so.6`__GI_raise(sig=6) at raise.c:26:13
    frame #2: 0x00007ffff72345fe libc.so.6`__GI_abort at abort.c:77:3
    frame #3: 0x00007ffff7235697 libc.so.6`__libc_message_impl(vma_name=<unavailable>, fmt=<unavailable>) at libc_fatal.c:138:3
    frame #4: 0x00007ffff72450b2 libc.so.6`__libc_message_wrapper(vmaname="", fmt=<unavailable>) at stdio.h:203:3 [inlined]
    frame #5: 0x00007ffff724507b libc.so.6`__assert_fail(assertion="size.width != 0", file="/home/aaron/Projects/OpenLoco/OpenLoco/src/OpenLoco/src/ViewportManager.cpp", line=<unavailable>, function=<unavailable>) at assert.c:37:3
    frame #6: 0x0000555555889afd OpenLoco`OpenLoco::Ui::ViewportManager::initViewport(origin=(x = 0, y = 0), size=(width = 0, height = 0), zoom=(level = '\0')) at ViewportManager.cpp:68:13
    frame #7: 0x0000555555889e93 OpenLoco`OpenLoco::Ui::ViewportManager::create(window=0x0000555556aa39a0, viewportIndex=0, origin=(x = 0, y = 0), size=(width = 0, height = 0), zoom=(level = '\0'), tile=OpenLoco::World::Pos3 @ 0x00007fffffffde3b) at ViewportManager.cpp:173:42
    frame #8: 0x00005555557c3715 OpenLoco`OpenLoco::Ui::Windows::Main::open() at Main.cpp:45:32
    frame #9: 0x000055555566405e OpenLoco`OpenLoco::Gui::init() at Gui.cpp:19:28
    frame #10: 0x00005555557071a6 OpenLoco`OpenLoco::initialise() at OpenLoco.cpp:197:18
    frame #11: 0x00005555557088d2 OpenLoco`OpenLoco::run() at OpenLoco.cpp:735:19
    frame #12: 0x0000555555708d09 OpenLoco`main(options=0x00007fffffffe040) at OpenLoco.cpp:829:16
    frame #13: 0x00005555557090ad OpenLoco`OpenLoco::main(argv=size=1) at OpenLoco.cpp:850:24
    frame #14: 0x00005555556913a9 OpenLoco`main(argc=1, argv=0x00007fffffffe308) at Main.cpp:12:26
    frame #15: 0x00007ffff72366c1 libc.so.6`__libc_start_call_main(main=(OpenLoco`main at Main.cpp:6:1), argc=1, argv=0x00007fffffffe308) at libc_start_call_main.h:59:16
    frame #16: 0x00007ffff72367f9 libc.so.6`__libc_start_main_impl(main=(OpenLoco`main at Main.cpp:6:1), argc=1, argv=0x00007fffffffe308, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe2f8) at libc-start.c:360:3
    frame #17: 0x000055555557f7a5 OpenLoco`_start + 37

This is on a machine with just an integrated GPU chipset.

@AaronVanGeffen
Copy link
Copy Markdown
Member

AaronVanGeffen commented Feb 19, 2026

On the latest version, the UI opens, and I can hear UI SFX for (invisible) windows opening. The canvas stays black, though. No console output beyond the version number either.

Screenshot 2026-02-19 at 19 21 55

@AaronVanGeffen
Copy link
Copy Markdown
Member

The good news is that it seems to have fixed Linux, at least.

Screenshot_20260219_203246

@AaronVanGeffen
Copy link
Copy Markdown
Member

Still getting a black screen on v26.01-21 (18c6952 on sdl3), sorry.

@AaronVanGeffen
Copy link
Copy Markdown
Member

Fixed by 9ce99c0. The most innocuous change! 😄

Screenshot 2026-02-22 at 19 21 40

Copy link
Copy Markdown
Member

@AaronVanGeffen AaronVanGeffen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good from my perspective. Maybe just rebase on top of current master to see if there are 'hidden' conflicts, i.e. not direct conflicts but surreptitious incompatibilities. There's probably nothing, but just to be on the safe side, right.

@AaronVanGeffen AaronVanGeffen modified the milestones: v26.02, v26.02+ Mar 6, 2026
@AaronVanGeffen AaronVanGeffen merged commit 67a1ff0 into OpenLoco:master Mar 7, 2026
14 checks passed
@ZehMatt ZehMatt deleted the sdl3 branch March 7, 2026 13:43
auto& drawingEngine = Gfx::getDrawingEngine();
drawingEngine.initialize(_window);
drawingEngine.resize(desc.width, desc.height);
drawingEngine.setVSync(cfg.vsync);
Copy link
Copy Markdown
Member

@AaronVanGeffen AaronVanGeffen Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This vsync call was probably lost in a rebase 😄 #3669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants