Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misaligned address SIGBUS in CGImageSourceCreateImageAtIndex #486

Open
MarcinKonowalczyk opened this issue Dec 8, 2024 · 9 comments
Open

Comments

@MarcinKonowalczyk
Copy link

MarcinKonowalczyk commented Dec 8, 2024

See this issue. I believe this is potentially a SDL_image bug??

Briefly;

  • working on mac M3, Sequoia 15.1.1.
  • trying to load a texture with texture = IMG_LoadTexture(renderer, "spritesheet.png");
  • getting a Job 1 terminated by signal SIGBUS (Misaligned address error)
  • traced it down to SDL_image/src/IMG_ImageIO.m to CreateCGImageFromCGImageSource to image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL); (docs)
  • changing 0 to -1 makes it work
  • printf("image_count: %lu\n", CGImageSourceGetCount(image_source)); prints 1
@MarcinKonowalczyk
Copy link
Author

MarcinKonowalczyk commented Dec 8, 2024

Working with the current head branch of SDL_image 33d18dd.

@slouken
Copy link
Collaborator

slouken commented Dec 8, 2024

That's really interesting. The documentation for CGImageSourceCreateImageAtIndex() says:

index
The zero-based index of the image you want. If the index is invalid, this method returns NULL.

It seems like -1 is an invalid index and the function would return NULL. Is that what happens?

@MarcinKonowalczyk
Copy link
Author

MarcinKonowalczyk commented Dec 8, 2024

Nope. I get an id of the ref to first image (which in this case is the spiresheet) and the game runs fine. Apple bug?? 🤨

@slouken
Copy link
Collaborator

slouken commented Dec 8, 2024

I'm not sure how that's possible... is there a bug in ImageIO where it's using -1 based indices?

@MarcinKonowalczyk
Copy link
Author

Just checked and it also works with image_ref = CGImageSourceCreateImageAtIndex(image_source, 99, NULL), as well as 1, -10, 42 and pretty much any garbage i come up with except for 0.

@MarcinKonowalczyk
Copy link
Author

The steps to reproduce for me are literally to follow the build instructions of this repo.

@MarcinKonowalczyk
Copy link
Author

Ok, i have some progress. I don't think it's SDL_image actually. So, this is very weird but, my default terminal is fish and there it does not work with 0, but it works no problem when i do bash -c ./build/Debug/flappybird aka when I run it though bash. Also works for zsh. Running fish 3.7.1. I checked that its nothing to do with my config.fish.

@MarcinKonowalczyk
Copy link
Author

MarcinKonowalczyk commented Dec 8, 2024

Just tried writing an issue on fish-shell GitHub and they suggest running with sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= XDG_DATA_DIRS= fish' which does fix the problem. I've narrowed it down to sh -c 'env HOME=$(mktemp -d) fish' which makes it work (also checked XDG_CONFIG_HOME and XDG_DATA_DIRS are the same between fish and bash and zsh.

Looks like something to do with my $HOME, but unsure what yet.

@MarcinKonowalczyk
Copy link
Author

Also managed to get a bit of crash report from Apple by launching through a different terminal. Here is the relevant bit:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGBUS)
Exception Codes:       UNKNOWN_0x101 at 0x000000000bad4007
Exception Codes:       0x0000000000000101, 0x000000000bad4007

Termination Reason:    Namespace SIGNAL, Code 10 Bus error: 10
Terminating Process:   exc handler [61103]

VM Region Info: 0xbad4007 is not in any region.  Bytes before following region: 4111826937
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      100c2c000-100c34000    [   32K] r-x/r-x SM=COW  /Users/USER/*/flappybird

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                           	         0xbad4007 ???
1   ImageIO                       	       0x1abbf6d60 IIOReadPlugin::callInitialize() + 388
2   ImageIO                       	       0x1abbf6b08 IIO_Reader::initImageAtOffset(CGImagePlugin*, unsigned long, unsigned long, unsigned long) + 164
3   ImageIO                       	       0x1abbf41a0 IIOImageSource::makeImagePlus(unsigned long, IIODictionary*) + 832
4   ImageIO                       	       0x1abc6d620 IIOImageSource::createImageAtIndex(unsigned long, IIODictionary*, int*) + 112
5   ImageIO                       	       0x1abc0109c CGImageSourceCreateImageAtIndex + 464
6   libSDL2_image-2.0d.0.900.0.dylib	       0x100ce4848 CreateCGImageFromCGImageSource + 152 (IMG_ImageIO.m:160)
7   libSDL2_image-2.0d.0.900.0.dylib	       0x100ce45c4 LoadImageFromFile + 80 (IMG_ImageIO.m:508)
8   libSDL2_image-2.0d.0.900.0.dylib	       0x100ce44f4 IMG_Load + 168 (IMG_ImageIO.m:587)
9   libSDL2_image-2.0d.0.900.0.dylib	       0x100ca77dc IMG_LoadTexture + 32 (IMG.c:307)
10  flappybird                    	       0x100c334f8 main + 772 (flappybird.c:1122)
11  dyld                          	       0x1a00bc274 start + 2840                          	       0x1a00bc274 start + 2840

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

No branches or pull requests

2 participants