|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chrisname (4922) | |||||||||
I'm playing around with SDL in C and for some reason; I'm getting a segfault using the pointer-to-member ('->') operator:
It is at the point where I use the arrow operator that it segfaults. Why is this? I always get segfaults using it; so obviously I'm doing something wrong. I googled it and I got this page http://boredzo.org/pointers/#structures and it looks to me like he's accessing a structure in the same way I am :l Here is the structure:
I thought for the moment that, though unlikely, it might be the typedef. I tried it like this:
it still segfaults, so obviously that wasn't the problem.
this also fails. | |||||||||
|
Last edited on
|
|||||||||
| Bazzy (6258) | |
| You aren't assigning sc to anything before using -> so you can't access it | |
|
|
|
| chrisname (4922) | |||
Huh? I have to assign it to the structure? Argh; I thought making it a pointer to that structure type would work :l
This seems to work for now, thanks :) | |||
|
Last edited on
|
|||
| Bazzy (6258) | |
| You may want to create an object dynamically | |
|
|
|
| chrisname (4922) | |||
|
Oh? As I say, I'm using C so I can't use new; although I guess I could "swap" to C++... Or can I do this with malloc() and free()?
? | |||
|
Last edited on
|
|||
| Bazzy (6258) | |
| malloc and free are the same (~) as new and delete in C++ | |
|
|
|
| chrisname (4922) | |
|
Yes; but they work differently. Or at least, you use them differently. In the snippet above, I free()'d scr after using it... It still works. Thanks :) I can't free() it for some reason... | |
|
Last edited on
|
|
| chrisname (4922) | |
|
Hmmm... I'm getting a segfault with something different now; whenever I call SDL_Flip it segfaults; but if I remove it, it doesn't :l Never mind. I wasn't handling the surfaces right. | |
|
Last edited on
|
|