SDL_GetRGBA is crashing

My program was working fine and then I moved some things around. Now it consistently crashes at SDL_GetRGBA().

SDL_Color *color_to_rgb(long color)
SDL_Color *RGB;
RGB = new SDL_Color;
[check for NULL]

SDL_GetRGBA (color, pixelformat, &RGB->r, &RGB->g, &RGB->b, &RGB->a);
return RGB;

Pixelformat is set as follows:

SDL_Surface *t2;
if((t2 = SDL_LoadBMP(buffer))==NULL)
[error and exit]

SDL_PixelFormat *pixelformat = t2->format;

Any ideas about what might be going wrong?

It’s almost certainly something pointer-related. As to what exactly, the first and best idea comes from the error message. Can you copy/paste it verbatim here?

I ran it in the debugger to get something useful.

Thread 1 received signal SIGSEV, Segmentation fault.
0x000007fecd50abb9 in SDL_DYNAPI_entry ()
from c:.…SDL2.dll

Yeah, segmentation fault is a pointer problem. SDL_DYNAPI_entry suggests that the problem is probably (but I’m not 100% certain about this) not in the code you presented here, but rather something’s going wrong with the dynamic library loading.

I think.

Can someone who knows the dynapi stuff better than me have a look at this?

I was looking through the code and found a place where I was accessing the wrong array. I fixed that, and things appear to be back to normal. Thanks for the responses.