Reputation: 1126
I have the following function using stbi_load:
void load_texture_from_file(const char *file, bool alpha, const char *name) {
Texture *tex;
tex = malloc(sizeof(Texture));
tex->name = name;
int width, height, channels;
unsigned char *data = stbi_load(file, &width, &height, &channels, 0);
generate_texture(width, height, data, tex, alpha);
stbi_image_free(data);
}
File is coming from:
load_texture_from_file("/home/correct_folder/correct_name.png", true, "sprite");
I get no error using stbi_failure_reason() and when checking the contents of data with gdb I see:
Thread 1 "a" hit Breakpoint 2, load_texture_from_file (file=0x555555579d18 "/home/correct_folder/correct_name.png",
alpha=true, name=0x555555579d12 "face") at resource_manager.c:25
25 generate_texture(width, height, data, tex, alpha);
(gdb) print data
$1 = (unsigned char *) 0x7ffff40c1010 ""
What am I missing?
Upvotes: 0
Views: 963
Reputation: 5265
To expand on @HolyBlackCat's comment, you may not be doing anything wrong at all in terms of loading the data. You should try examining memory with gdb instead of print
ing it, which is treating data
as as string. You can do so in gdb with the following command:
x/nfu <address>
where
x/
is the "examine memory" commandn
is the number of memory units/elements you want to examinef
is the display format ('x' for hex, 'd' for decimal, etc. See link below)u
is the unit/element format ('b' for bytes, 'w' for words, etc. See link below)address
is the address where you want to begin examining memoryFor example, to look at the first 5 bytes of data
in hex format, you would enter
x/5xb data
To look at the first ten 4-byte words in hex format, you would enter
x/10xw data
See this page for more information and an exhaustive list of all parameter options.
Upvotes: 1