Re: Widelands crash fix

2023-09-29 Thread Thomas Frohwein
On Fri, Sep 29, 2023 at 04:17:54AM -0600, Anthony J. Bentley wrote:
> 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?

Tested on my Intel Tigerlake iGPU system and still works, so ok thfr@

> 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 -  1.38
> +++ Makefile  29 Sep 2023 09:51:01 -
> @@ -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 -
> +++ patches/patch-src_graphic_texture_cc  29 Sep 2023 09:51:01 -
> @@ -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(surface->pixels));
> + 
> + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(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);
> 



Widelands crash fix

2023-09-29 Thread Anthony J. Bentley
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
--- Makefile28 Sep 2023 20:50:51 -  1.38
+++ Makefile29 Sep 2023 09:51:01 -
@@ -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 -
+++ patches/patch-src_graphic_texture_cc29 Sep 2023 09:51:01 -
@@ -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(surface->pixels));
+ 
+   glTexImage2D(GL_TEXTURE_2D, 0, static_cast(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);