We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2296

Summary: SDL_GL_UnbindTexture segfaults on osx
Product: SDL Reporter: Daniel Bünzli <daniel.buenzli>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq
Version: 2.0.1   
Hardware: x86   
OS: Mac OS X 10.8   

Description Daniel Bünzli 2013-12-11 13:10:05 UTC
The program at the end of the report segfaults on the call to SDL_GL_UnbindTexture().

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000034
0x000000010003c3ea in GL_UnbindTexture ()
(gdb) bt
#0  0x000000010003c3ea in GL_UnbindTexture ()
#1  0x0000000100000e29 in main ()

Looking at the code of SDL_GL_BindTexture(), I see there's a special path whenever texture->native is true that is not present in SDL_GL_UnbindTexture is that maybe the problem ? 

Best,

Daniel



#include <unistd.h>
#include "SDL.h"
#include <assert.h>
int main(int argc, char** argv)  
{
  SDL_Init(SDL_INIT_VIDEO);

  SDL_Window *w = SDL_CreateWindow
    ("SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
     640, 480, SDL_WINDOW_OPENGL);
  assert (w);
  
  SDL_GLContext *c = SDL_GL_CreateContext(w);
  assert (c);
  SDL_GL_MakeCurrent(w,c);

  SDL_Renderer *r = SDL_CreateRenderer(w, 0, 0);
  assert (r);

  SDL_Texture *t = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888, 
                                     SDL_TEXTUREACCESS_STATIC, 256, 256);
  assert(t);
  SDL_GL_BindTexture(t, NULL, NULL);
  SDL_GL_UnbindTexture(t); /* BOOM */
 
  SDL_DestroyTexture(t);
  SDL_DestroyRenderer(r);
  SDL_GL_DeleteContext(c);
  SDL_DestroyWindow(w); 
  SDL_Quit(); 
  return 0;   
}
Comment 1 Gabriel Jacobo 2014-02-24 21:58:03 UTC
Fixed, thanks! https://hg.libsdl.org/SDL/rev/294f28074ecc