Port to SDL2

Bug #1380048 reported by SirVer
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
High
Unassigned

Bug Description

SDL2 has more features, is more stable, gives easier support for mobile platforms and is the only version of SDL that is still supported and developed. Reasons enough to port.

Martin has worked on this and seems to have done it already here: https://code.launchpad.net/~widelands-dev/widelands/feature-3d-rendering-open-gl-es-compat

But it seems that he tried to do too much in the branch and eventually lost interest - so this was never merged. I think about a minimal evasive port - if possible swapping out each library one by one (i.e. port to SDL2 core, but keep libsdl-net at the earlier version. Not sure if this is possible though).

Looking at the features of SDL2, it seems like we can loose the dependency on sdlgfx with it too.

Related branches

Revision history for this message
SirVer (sirver) wrote :

Gun, I assigned you because you are such a busy bee these days. And this is quite important :).

Revision history for this message
SirVer (sirver) wrote :

Feel free to unassign of course...

Revision history for this message
Hans Joachim Desserud (hjd) wrote :

(Might be revelant, might not be.)

Another project I follow is Flare (short for Free/Libre Action Roleplaying Engine). It's pretty cool and people should check it out. Anyways, the reason I mention it, is because it's written in C++, use CMake for building and have ported from SDL to SDL2. Looking at their CMakeLists.txt at https://github.com/clintbellanger/flare-engine it doesn't seem that complicated, and they even have a fallback to SDL for platforms where SDL2 isn't available for various reasons. Might be worth to take a look at, since it use much of the same stack.

(I should mention I didn't follow the porting work in detail, but I can't remember hearing of any major problems along the way. Or problems with the fallback to older SDL libraries)

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the hint. I have no idea what is to do here exactly, but will investigate.

Revision history for this message
SirVer (sirver) wrote :
Revision history for this message
GunChleoc (gunchleoc) wrote :

Link to migration guide for reference: https://wiki.libsdl.org/MigrationGuide

Revision history for this message
GunChleoc (gunchleoc) wrote :

The state of thing: I can start a game and play, no problem. I have also tested starting a LAN game and loading a replay.

However, when I exit Widelands, I get a segfault, and changed options aren't written. I also get to see this when leaving Widelands:

*** Error in `./widelands': free(): invalid pointer: 0x00007fa7abce75fd ***

How do I track this down?

Revision history for this message
SirVer (sirver) wrote :

I usually litter the code with ALIVE debug output to bisect where this crash happens. More often than not debuggers are not super useful in traps like these.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have never used a debugger in my life, I always print to console to find stuff. I have no idea where in to code to start though, since I just copied stuff over from Marten's branch. I guess I'll just have to try to find the main control flow for the exit routine to start searching.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Found it :)

Still need to go over the font rendering with a fine-tooth comb, list elements and loading screens don't look good.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I think this is done now and ready for testing. We should probably look at all OS's before I send a merge request. @Tino: will you do the honours for Windows?

Changed in widelands:
assignee: GunChleoc (gunchleoc) → Tino (tino79)
Revision history for this message
SirVer (sirver) wrote :

I fixed a couple of issues that I saw on Mac OS. I still see a bunch of more issues:

- scroll wheel is not working in menus
- When i try to start a multiplayer game (i.e. internet gaming -> log in to server -> open new game) the game crashes when I come to the map select screen with an image not found error.

On the positive side, compiling, starting the game, graphics (with and without opengl) and sound seem to be working great :).

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for testing. I'll have another look at it when I get back to my dev machine.

Revision history for this message
Tino (tino79) wrote :

Ok, it does also work on windows.
One regression:
Widelands does no longer produce a stdout.txt and a stderr.txt : http://forums.libsdl.org/viewtopic.php?t=9454
While it is possible to force a stdout.txt with the --logfile option, the stderr.txt with the infos from exceptions is lost it seems.

Changed in widelands:
assignee: Tino (tino79) → nobody
Revision history for this message
GunChleoc (gunchleoc) wrote :

I'll look into the SDL_Messagebox thing. I text can be copy/pasted from there, that might be the best case for replacing the stderr.txt, I think.

Changed in widelands:
assignee: nobody → GunChleoc (gunchleoc)
Revision history for this message
GunChleoc (gunchleoc) wrote :

- scroll wheel is not working in menus

This happens because handle_mousewheel is called for panel.h instead of the actual inherited object (e.g. table or listselect) - I tried working with virtual + override, but that doesn't change a thing.

- When i try to start a multiplayer game (i.e. internet gaming -> log in to server -> open new game) the game crashes when I come to the map select screen with an image not found error.

I can't reproduce this. What's the image?

Revision history for this message
SirVer (sirver) wrote :

[scrollwheel]

using virtual is the way to go though. That should work. Can you point me to the point where it is not working?

[crash]

nevermind. The crash is in trunk too. I opened bug 1385859 for that.

Revision history for this message
GunChleoc (gunchleoc) wrote :

[scrollwheel]

I have isolated the problem, which is in Panel::do_mousewheel.

It is working for focussed panels now, but I don't know how to fix it in general.

Revision history for this message
SirVer (sirver) wrote :

The scrollwheel behaves the same now for me as in trunk, so this is fixed.

Revision history for this message
SirVer (sirver) wrote :

I reviewed the code and it lgtm - ship it and congratulations for doing one of the most important porting work in the history of Widelands :). We can now try to compile widelands for android - exciting!

Revision history for this message
GunChleoc (gunchleoc) wrote :

Well, it doesn't for me - in trunk, I can use the scrollwheel to scroll the language list in Options. In the SDL2 branch, I can't.

Since we don't have any menus with 2 scrolling elements, we could fake it for now by giving them focus, but that's a dirty hack. I'd be happy to do this for now so we can get this branch in, but we should take not of this to fix in the future.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I spoke too soon: When loading a map, the description can also have a scrollbar, so we have 2 scrollbars in one window here. So, we do need to fix this.

Revision history for this message
SirVer (sirver) wrote :

The branch is huge already though and it is a fundamental change for packagers, maintainers and so on. I vote for merging now and opening regression tracking bugs to fix the scrollwheel behavior.

One more feature that we need to change is to use the SDL2 logging for in our own log() method so that we can still get logging information on Windows. This should also get it's own bug.

Revision history for this message
GunChleoc (gunchleoc) wrote :

OK, I'll add the focus hack merge this then and open new bugs for the remaining issues.

SirVer (sirver)
Changed in widelands:
status: Confirmed → Fix Committed
GunChleoc (gunchleoc)
Changed in widelands:
assignee: GunChleoc (gunchleoc) → nobody
GunChleoc (gunchleoc)
Changed in widelands:
status: Fix Committed → Fix Released
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build19-rc1.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.