Skip to content

Remove unused code from library_sdl.js. NFC #18986

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

Merged
merged 1 commit into from
Mar 17, 2023
Merged

Remove unused code from library_sdl.js. NFC #18986

merged 1 commit into from
Mar 17, 2023

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 16, 2023

This came out of the work I'm doing on #18979

  • SDL_malloc/SDL_free are not declared in the SDL header but instead defined to malloc/free (because we define HAVE_MALLOC).
  • Mix_PlayChannel is defined to Mix_PlayChannelTimes in the header.
  • SDL_BlitScaled/SDL_BlitSurface are defined to SDL_UpperBlitScaled and SDL_UpperBlit respectively.
  • SDL_UnlockMutex and SDL_LockMutex are defined to SDL_mutexV and SDL_mutexP.
  • SDL_LoadBMP is defined as SDL_LoadBMP_RW

This came out of the work I'm doing on #18979

- SDL_malloc/SDL_free are not declared in the SDL header but instead
  defined to malloc/free (because we define HAVE_MALLOC).
- Mix_PlayChannel is defined to Mix_PlayChannelTimes in the header.
- SDL_BlitScaled/SDL_BlitSurface are defined to SDL_UpperBlitScaled
  and SDL_UpperBlit respectively.
- SDL_UnlockMutex and SDL_LockMutex are defined to SDL_mutexV and
  SDL_mutexP.
- SDL_LoadBMP is defined as SDL_LoadBMP_RW
@sbc100 sbc100 requested a review from kripken March 16, 2023 23:38
@sbc100 sbc100 enabled auto-merge (squash) March 16, 2023 23:47
@sbc100 sbc100 merged commit ffa2a51 into main Mar 17, 2023
@sbc100 sbc100 deleted the cleanup_sdl_js branch March 17, 2023 01:47
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
This came out of the work I'm doing on emscripten-core#18979

- SDL_malloc/SDL_free are not declared in the SDL header but instead
  defined to malloc/free (because we define HAVE_MALLOC).
- Mix_PlayChannel is defined to Mix_PlayChannelTimes in the header.
- SDL_BlitScaled/SDL_BlitSurface are defined to SDL_UpperBlitScaled
  and SDL_UpperBlit respectively.
- SDL_UnlockMutex and SDL_LockMutex are defined to SDL_mutexV and
  SDL_mutexP.
- SDL_LoadBMP is defined as SDL_LoadBMP_RW
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
This came out of the work I'm doing on emscripten-core#18979

- SDL_malloc/SDL_free are not declared in the SDL header but instead
  defined to malloc/free (because we define HAVE_MALLOC).
- Mix_PlayChannel is defined to Mix_PlayChannelTimes in the header.
- SDL_BlitScaled/SDL_BlitSurface are defined to SDL_UpperBlitScaled
  and SDL_UpperBlit respectively.
- SDL_UnlockMutex and SDL_LockMutex are defined to SDL_mutexV and
  SDL_mutexP.
- SDL_LoadBMP is defined as SDL_LoadBMP_RW
@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 6, 2024

Oops, I guess we are missing some test coverage there. Thanks for the report, I'll take a look. Can I ask how you are using that function? Can you share what the call site looks like?

@ClintKilmer
Copy link

ClintKilmer commented Feb 7, 2024

Here was my original post:

I believe that this change broke SDL_LoadBMP. In my project, I now have to use SDL_LoadBMP_RW, -or- downgrading the emsdk version.

SDL_LoadBMP error: Parameter 'src' is invalid


Upon further testing, both SDL_LoadBMP and SDL_LoadBMP_RW are broken in v3.1.42 - v3.1.53, and are fixed by downgrading to v3.1.41 or earlier. Using the latest SDL3 emscripten static lib by the way.

Here's what the code looks like:

SDL_Surface* sword = SDL_LoadBMP("sword.bmp");

SDL error: Parameter 'src' is invalid

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 7, 2024

Was SDL3 a typo there?

@ClintKilmer
Copy link

Nope

@ClintKilmer
Copy link

Update:
Worked in v3.1.41 and older
Broken in v3.1.42 and newer

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 7, 2024

Thanks for the update. This PR landed in 3.1.35 so I suppose there is a different cause of the error.

If you get a change and you have the repro handy perhaps you could bisect further between 3.1.41 and 3.1.42 (https://emscripten.org/docs/contributing/developers_guide.html#bisecting)?

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 7, 2024

What is "SDL3 emscripten static lib" ? Does this reproduce with emscripten's -sUSE_SDL2?

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 7, 2024

SDL error: Parameter 'src' is invalid looks like it has to come from SDL_InvalidParamError in SDL_LoadBMP which means that first argument is NULL which means that SDL_RWFromFile failed in this macro:

#define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)

So.. the file could not be read.. but we don't know why yet..

@ClintKilmer
Copy link

First of all, thank you for all your help.

This does not reproduce with emscripten's -sUSE_SDL2.
Seems to only be present in the automated "Build (Emscripten)" action in the SDL3 GitHub.

I can also confirm that SDL_RWFromFile is the culprit (same error message for SDL_LoadBMP, SDL_LoadWAV, and SDL_RWFromFile). Perhaps I should create an issue over on the SDL repo, although they seem to be in rapid development mode at the moment.

My current workaround while developing for SDL3 Emscripten is to stay on v3.1.41.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 7, 2024

I think this does sounds like an emscripten regression so it probably makes sense to open an issue here.

If you get time to bisect between v3.1.41 and v3.1.42 that would be great.. or a small repro would be great too.

How are you embedding you data files by the way (i.e. how is it the files are injected into the emscripten VFS)?

@ClintKilmer
Copy link

emcc -regular compilation stuff- --preload-file sword.bmp --use-preload-plugins

I'll work on bisecting or a repro soon.

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.

3 participants