Using windowed mode (works fine in fullscreen) on SDL in OSX Mojave with SDL_image I load a png. The png loads fine but I notice green artifacts across the screen. Note: This happens with SDL_LoadBMP as well. Does anyone else experience this?
Using your sample code, I didn’t get a green line, but it did act weird, like it wasn’t finished setting up the window. Then I noticed you aren’t going through the whole event queue every frame. Change the start of your main loop to something like
bool quit = false;
while(quit) {
// Check every event on the event queue
while(SDL_PollEvent(&windowEvent)) {
if(windowEvent.type == SDL_QUIT) {
quit = true;
}
}
Once I did this it worked fine.
Also you don’t need to free windowSurface. The SDL_GetWindowSurface() docs explicitly say not to free the returned surface.
I had the same exact issue yesterday with macOS Mojava. I thought it was an issue with Mojave but I copy pasted lazyfoo’s code and when I rendered that it started working. Also there is an issue in Moajve where you have to drag the window a bit for renderer to start.
@sjr Thanks for the quick response! Sorry I had been busy with work this past weekend. I added the code to make sure I was running through all of the event queue and removed the line that frees up the windowSurface. I got slightly different artifacts one time, and then it went back to the normal issue.
I tried SDL_FillRect before the Blit call, and sure enough there’s a nice clean black background!
No, your sprite not covering the whole window shouldn’t matter. The window surface may not be getting cleared when created, and thus is filled with garbage. Which seems strange, but maybe you’ve encountered a weird bug. Seems like it should be random garbage in that case, though, not mostly black.
Either way, calling SDL_FillRect() fills it with black.
Depending on what you’re doing, it might be better to only clear it once and then use dirty rects. Or (best option) switch to the hardware accelerated renderer.
I got further along in my reading and ran into the hardware accelerated renderer you mentioned. This appears to function perfectly within my environment and definitely would be the best option