• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Dumb question about sprite_add(...) and .gifs

D

direstatus

Guest
While writing a image gallery/viewer application, I encountered a problem that is giving me a headache.

The problem: Can't load .gif files via sprite_add(...)

I attempted to add a .gif via sprite_add(...) but I encountered a "Stack overflow..." dialog with message: "gml_Object_object0_Draw_0" ...(object0 seems to reference the calling object).

Background: Documentation states that .gif files can be added via sprite_add(...) but that all arguments except for fname should be 0. Granted this I'm expecting a sprite of the first frame of the .gif to be loaded as long as I provide a valid fname. fname is confirmed via file_exists(...) or by manually checking the working_directory and %appdata%/local/game_name folder while ensuring originals are in projectfile/datafiles/.../ directory (as far as I know, this is as much as you can do to confirm files are where GM can find them). I expect to be able to display this .gif via the conventional method of draw_sprite(...). I cannot due to a stack overflow.

Attempted Solutions:
Made a blank project, with 1 room, 1 object, 1 included file. The object is persistently placed into the room and attempts to assign the included file ("img1.gif") to a sprite via sprite_add(...) using the following script...

Code:
spr1 = sprite_add('img1.gif',0,0,0,0,0);
draw_sprite(spr1,0,0,0);
I tried various combinations of arguments but that changed nothing. Since I can't even get a simple script like this to work, I don't know where else I can go from here. I must be missing something basic.

Additional Background Info:
Initially encountered when writing a image viewer application. Application handles .png and .jpg as expected, it reads filenames out of a .ini file and grabs the referenced files from project included files, and gracefully handles missing files/corrupted .ini files (I like to wreck-test my applications and data files). Everything performs fine until .gifs are introduced.

I've been stuck on this problem for a hour or so. I've made sure to reference the tutorials and the documentation to ensure I didn't make a obvious technical mistake so I'm assuming I've made a more general mistake I can't see because of my noobiness.

Initially I assumed I made a mistake in my for() loops somewhere because of the stack overflow, giving me a for loop that ran until memory ran out. I removed the for loops again and again until I found the source of the error to be a section of code that worked fine until now, but broke as soon as it tried to load a .gif. Unable to find a reasonable solution as to why this was I made a new project to try and load the problematic .gif directly, without any possibility of my other code interfering. Once that failed I tried other .gifs thinking that the original test .gif may have been problematic (should have done this sooner) but that ended up not mattering. Still failed. Turned out to fail no matter what size or type of .gif was loaded. Decided to make this forum post to find help.
 

CloseRange

Member
A stack overflow occurs when too much memory is used on the call stack and when your game attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to overflow, resulting in a program crash. Restart your computer and GameMaker: Studio and if the error persists please get in touch with support and/or file a bug (as explained above).
that can help a bit.

You're not giving all the info. I have a room (room0) an object (obj_test) and an included file (giphy.gif).
In the draw event of obj_test is this:
Code:
spr1 = sprite_add('giphy.gif',0,0,0,0,0);
draw_sprite(spr1,0,0,0);
and the image shows up perfectly (but it lags because you should never have sprite_add in the draw event like that)
 
D

direstatus

Guest
that can help a bit.

You're not giving all the info. I have a room (room0) an object (obj_test) and an included file (giphy.gif).
In the draw event of obj_test is this:
Code:
spr1 = sprite_add('giphy.gif',0,0,0,0,0);
draw_sprite(spr1,0,0,0);
and the image shows up perfectly (but it lags because you should never have sprite_add in the draw event like that)
Appreciate the response. I have restarted my PC and GM:S and no joy. I should have mentioned in the OP that I already did everything the documentation suggested but I thought saying I'd read the documentation would imply that. But I tried again anyway after your comment and like I said, no luck ):. I was mainly hoping someone else had encountered this problem before and had a solution, because Google hasn't provided any relevant results. I'm going to attempt a clean install of GM and safely wiping all projects and see if that helps. I'll reply if it does, for the sake of anyone else who has this problem in future.

edit: reinstalling GM had no effect. Still hoping I've messed up some basic configuration/etc. stuff that'd explain this. I'll be getting in contact with YYG tomorrow as well
 
Last edited by a moderator:
Top