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
SDL_LoadFile() Linux segmentation fault reading datasize #5394
Comments
@logos-maker |
I tried with the following, can't get a segfault. Must see the particular test case from @logos-maker #include "SDL.h"
#include <stdio.h>
int main (int argc, char **argv) {
SDL_RWops *rw;
void *loaded;
size_t sz;
if (argc != 2) {
return 1;
}
rw = SDL_RWFromFile(argv[1], "rb");
if (!rw) {
fprintf(stderr, "Failed opening %s\n", argv[1]);
return 1;
}
loaded = SDL_LoadFile_RW(rw, &sz, 1);
if (!loaded) {
fprintf(stderr, "Failed loading from %s\n", argv[1]);
return 1;
}
SDL_free(loaded);
fprintf(stderr, "DATASIZE: %lu\n", (unsigned long)sz);
return 0;
} |
The code by sezero gives the size even if it isn't a file in the same directory as the program. So it works fine.
...but that didn't give the segmentation fault. But the same code still gives a segmentation fault if I have a window open and drops a file on the window. I'm not sure whats happening. I'll have some code that I will post that recreates the problem. Or is the code above faulty, but gives the right result by some fluke? |
The code bellow recreates the problem. And then it also gives a segmentation fault if you give a file name in the terminal. So that's strange.
|
Your test code is definitely wrong:
What you want is this: #include "SDL.h"
#include <stdio.h>
int main (int argc, char **argv) {
void *loaded;
size_t sz;
if (argc != 2) {
return 1;
}
loaded = SDL_LoadFile(argv[1], &sz);
if (!loaded) {
fprintf(stderr, "Failed loading from %s\n", argv[1]);
return 1;
}
SDL_free(loaded);
fprintf(stderr, "DATASIZE: %lu\n", (unsigned long)sz);
return 0;
} ... which works just fine:
Closing as invalid. |
What sezero says is the way to do it doesn't even compile.
|
Look carefully at how I define |
Thanks!!! |
When reading the length pointed to to get the datasize, I get a segmentation fault. This only seams to occur if I have a path for the file, but not if the file is in the working directory. But I can still read the data from the file but not get the length as I will get a segmentation fault. So I can read the pointer but not the length that it points to.
It looks like my system is using version 2.0.10
The text was updated successfully, but these errors were encountered: