Friday, September 29, 2023

Widelands crash fix

volker's recent commit to widelands didn't fix the crash I'm seeing.
That makes sense, because we compared backtraces and the crash he saw
was totally different.

Backporting this patch (labeled as "for Mesa 23.x") fixes my crash.

ok?

Index: Makefile
===================================================================
RCS file: /cvs/ports/games/widelands/Makefile,v
retrieving revision 1.38
diff -u -p -r1.38 Makefile
--- Makefile 28 Sep 2023 20:50:51 -0000 1.38
+++ Makefile 29 Sep 2023 09:51:01 -0000
@@ -3,7 +3,7 @@ COMMENT = economic and military simulati
GH_ACCOUNT = widelands
GH_PROJECT = widelands
GH_TAGNAME = v1.0
-REVISION = 2
+REVISION = 3

CATEGORIES = games

Index: patches/patch-src_graphic_texture_cc
===================================================================
RCS file: patches/patch-src_graphic_texture_cc
diff -N patches/patch-src_graphic_texture_cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_graphic_texture_cc 29 Sep 2023 09:51:01 -0000
@@ -0,0 +1,39 @@
+Backport Mesa 23.x fix from upstream.
+https://github.com/widelands/widelands/commit/48e5fd48c3f6418ebb53a145177d0417dc96451b
+
+Index: src/graphic/texture.cc
+--- src/graphic/texture.cc.orig
++++ src/graphic/texture.cc
+@@ -116,9 +116,11 @@ Texture::Texture(SDL_Surface* surface, bool intensity)
+ uint8_t bpp = surface->format->BytesPerPixel;
+
+ if (surface->format->palette || width() != surface->w || height() != surface->h ||
+- (bpp != 3 && bpp != 4) || is_bgr_surface(*surface->format)) {
++ (bpp != 4) || is_bgr_surface(*surface->format)) {
+ SDL_Surface* converted = empty_sdl_surface(width(), height());
+- assert(converted);
++ if (converted == nullptr) {
++ throw wexception("Failed to create SDL_Surface");
++ }
+ SDL_SetSurfaceAlphaMod(converted, SDL_ALPHA_OPAQUE);
+ SDL_SetSurfaceBlendMode(converted, SDL_BLENDMODE_NONE);
+ SDL_SetSurfaceAlphaMod(surface, SDL_ALPHA_OPAQUE);
+@@ -127,16 +129,15 @@ Texture::Texture(SDL_Surface* surface, bool intensity)
+ SDL_FreeSurface(surface);
+ surface = converted;
+ bpp = surface->format->BytesPerPixel;
++ assert(bpp == 4);
+ }
+
+- const GLenum pixels_format = bpp == 4 ? GL_RGBA : GL_RGB;
+-
+ SDL_LockSurface(surface);
+
+ Gl::swap_rows(width(), height(), surface->pitch, bpp, static_cast<uint8_t*>(surface->pixels));
+
+ glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(intensity ? GL_INTENSITY : GL_RGBA), width(),
+- height(), 0, pixels_format, GL_UNSIGNED_BYTE, surface->pixels);
++ height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
+
+ SDL_UnlockSurface(surface);
+ SDL_FreeSurface(surface);

No comments:

Post a Comment