ENIGMA Forums

Outsourcing saves money => Issues Help Desk => Topic started by: RobotiX on January 17, 2015, 10:18:52 pm

Title: sprite_add not working?
Post by: RobotiX on January 17, 2015, 10:18:52 pm
Hey all,

I have lots of GM experience but only recently started with ENIGMA. I started a project from scratch in LGM, it's the newest ENIGMA portable, I have jdk 8, running Windows 7.
Basically I have:
Code: [Select]
image = sprite_add(file_name, 0, false, false, 0, 0)
show_message(string(image))
And then in the draw event:
Code: [Select]
draw_sprite(image, 0, x, y)I get the message and it shows the sprite index but when it tries to call the draw function the game crashes.
Any help would be appreciated.

RobotiX
Title: Re: sprite_add not working?
Post by: Darkstar2 on January 18, 2015, 01:45:43 am
Even in GMS 1.4 latest this does not work, returns error "cannot display non existing sprite"

I  obvously replaced file name with an image file in the same directory as the compiled exe.

Interesting.
Title: Re: sprite_add not working?
Post by: RobotiX on January 18, 2015, 02:21:57 am
It works perfectly in GM 8.

EDIT:
Ok so I managed to get an error in the console, it said something along the lines as "incorrect PNG signature, it's no PNG or corrupted" So i thought maybe ENIGMA can only handle pngs. No problem, I just converted my image to a png. Still crashes, no error message this time. So I just ran gdb on it and got this:

Code: [Select]
Program received signal SIGFPE, Arithmetic exception.
0x004de1de in enigma::sprite_add_to_index (ns=0x6b391f8, filename=...,
    imgnumb=0, precise=false, transparent=false, smooth=false, x_offset=0,
    y_offset=0, mipmap=false) at Universal_System/spritestruct.cpp:285
285             unsigned cellwidth = width/imgnumb;

and the backtrace:

Code: [Select]
#0  0x004de1de in enigma::sprite_add_to_index (ns=0x6b391f8, filename=...,
    imgnumb=0, precise=false, transparent=false, smooth=false, x_offset=0,
    y_offset=0, mipmap=false) at Universal_System/spritestruct.cpp:285
#1  0x004dd066 in enigma_user::sprite_add (filename=..., imgnumb=0,
    precise=false, transparent=false, smooth=false, preload=true, x_offset=0,
    y_offset=0, mipmap=false) at Universal_System/spritestruct.cpp:68
#2  0x004dd1b6 in enigma_user::sprite_add (filename=..., imgnumb=0,
    transparent=false, smooth=false, x_offset=0, y_offset=0, mipmap=false)
    at Universal_System/spritestruct.cpp:74
#3  0x0040351b in enigma::OBJ_obj_0::myevent_create (this=0x6b38d78)
    at C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfu
nctionality.h:43
#4  0x004e61c1 in enigma::roomstruct::gotome (
    this=0x7ef3e0 <enigma::grd_rooms>, gamestart=true)
    at Universal_System/roomsystem.cpp:193
#5  0x004ea4e9 in enigma::game_start () at Universal_System/roomsystem.cpp:841
#6  0x004b2a0f in enigma::initialize_everything ()
    at Universal_System/loading.cpp:120
#7  0x00407a76 in WinMain@16 (hInstance=0x400000, hPrevInstance=0x0,
    lpCmdLine=0x1ed6386 "", iCmdShow=10)
    at Platforms/Win32/WINDOWSmain.cpp:255
#8  0x0076a48d in main ()

It looks like a problem with ENIGMA.

EDIT AGAIN:
Fixed it. looking at the error it says "Arithmetic exception." and "width/imgnumb" I put two and two together and guessed that it was a divide-by-zero error, I changed image_num to 1 instead of 0 and it didn't crash.
Thanks Obama.
Title: Re: sprite_add not working?
Post by: TheExDeus on January 18, 2015, 03:07:33 pm
Yup, we need better error checking. Many parts of the code don't do any checks even in debug mode. We need to add a special error window and than add many more checks.

And we support png's, bmp's and most recently gif's. They are all identified by the extension of the file and default's to bmp.
Title: Re: sprite_add not working?
Post by: RobotiX on January 18, 2015, 03:15:54 pm
Yeah, anytime something is divided by user input it should first check to see if it's zero. But I understand you guys already have massive amounts of work to be done. Overall I am EXTREMELY impressed. I fixed that error and the game I ported from GM ran perfectly. Except for sound_fade...
Title: Re: sprite_add not working?
Post by: TheExDeus on January 18, 2015, 04:46:42 pm
Our idea is not to test things like that in normal Run mode. They will only be checked in debug mode, and in a lot of cases it is (like all the drawing functions check if the resource exists only in debug mode, in regular or release mode it will not check that). So you will still have a million ways to crash even if we implement it all fully.

Sound fade might not be implemented fully. You can try DirectSound and see if it's there. In OpenAL I think we don't support any sound effects, as there is no easy way to add them in OpenAL.
Title: Re: sprite_add not working?
Post by: Goombert on January 18, 2015, 06:21:12 pm
Quote from: RobotiX
Thanks Obama.
lol, Howdy, I am Robert and I have done a lot of contributing here so I may be able to clarify some things for you.

Currently OpenAL attempts to implement both the basic sound functions and DirectSound functions, however we eventually plan to drop support for the sound_* functions unless you use the DirectSound system. audio_* functions are from GM: Studio which uses OpenAL and is better for both cross-platform development as well as positional audio, DirectSound is deprecated by Microsoft. The original sound_* functions from GM 8.1 and earlier were implemented with DirectSound and mp3 files were played using DirectMusic which is an interface for Windows Media Player (hence the old option to use an external media player). ENIGMA's DirectSound system does not implement DirectMusic yet so it only supports basic WAV formats. I am certain our OpenAL system supports OGG, WAV, and MP3 because we built it with those codecs.

I am sorry you encountered the bug ENIGMA certainly needs better error handling, and there is discussion about the interface design for it but that is mainly in the context of compile-time errors and not run-time errors. There have been some things I have been planning regarding ENIGMA's run-time exceptions and that is mainly to provide a stack trace with line numbers in the function show_debug_message like LateralGM's exception dialog. One place we have improved recently is that undefined variables can actually report scope in debug mode, which was a huge improvement.
Title: Re: sprite_add not working?
Post by: RobotiX on January 19, 2015, 01:53:04 am
Oh I know who you are and I am grateful.
I get a "Unknown function or script `sound_fade'" error regardless of which sound system I'm using.
I made a pretty hacky GML alternative that increments or decrements the volume and sets it using sound_volume(). sound_get_volume() also doesn't seem to work so I just use a variable to store the the current value and manipulate that.
Title: Re: sprite_add not working?
Post by: Darkstar2 on January 19, 2015, 11:23:05 am
Since the topic was about sprite_add,

Robert, any idea why sprite_add no longer works ? It used to.

I also tried it, it crashes, it works only with GIF, but with PNG it crashes, and yes I am using proper settings, tried all possible combinations, different PNG, etc.

After months of not using ENIGMA, I started playing around with it and notice how far more unstable it has become, just after half a dozen save/updating I get memory access JVM errors in LGM and crashing/closing.......I have 16GB of RAM, 14GB free, and yes I use the 1000 max in settings.ini, and some functions that used to work fine now either don't work at all or fail/crash.
sprite_add one of them.

Title: Re: sprite_add not working?
Post by: Goombert on January 19, 2015, 03:06:27 pm
Quote from: Darkstar2
Robert, any idea why sprite_add no longer works ? It used to.
Does this answer your question?
Quote from: RobotiX
EDIT AGAIN:
Fixed it. looking at the error it says "Arithmetic exception." and "width/imgnumb" I put two and two together and guessed that it was a divide-by-zero error, I changed image_num to 1 instead of 0 and it didn't crash.
Thanks Obama.
It's not broke and it hasn't been broke since I broke it to fix it.

Quote from: RobotiX
I get a "Unknown function or script `sound_fade'" error regardless of which sound system I'm using.
It looks like we never actually even outlined the function. I can give you the basic steps to add it though.
First outline the function in the general header https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Audio_Systems/General/ASbasic.h#L62
it should be the same path in your local enigma-dev copy regardless of how you installed. By outlining it there it ensures the parameter and return types are the same for every system.
Then you just add the body of the function in https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Audio_Systems/DirectSound/DSbasic.cpp#L92
or https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Audio_Systems/OpenAL/ALbasic.cpp#L152
for OpenAL. That's really all you need to do and the function will be usable, you could also send us a pull request on GitHub and we may merge it so long as you write the code neatly to match the other functions in the files.

Quote from: GM8.1 Manual
sound_fade(index,value,time) Changes the volume for the indicated sound to the new value(0 = low, 1 = high) during the indicated time (in milliseconds). This can be used to fade out or fade in music.
Title: Re: sprite_add not working?
Post by: Darkstar2 on January 19, 2015, 09:51:59 pm
lol perhaps you didn't read the part in my post where I said I tried all possibilities still did not load the PNG. By all possibilities means yes I tried the 1 instead of 0 also.

Quote
and yes I am using proper settings, tried all possible combinations, different PNG, etc.

Title: Re: sprite_add not working?
Post by: Goombert on January 19, 2015, 09:54:52 pm
Do you have the PNG? I'll test myself, Project Mario uses extensive BMP and PNG loading. Also the code that you are trying to load it with.
Title: Re: sprite_add not working?
Post by: Darkstar2 on January 19, 2015, 09:58:18 pm
Do you have the PNG? I'll test myself, Project Mario uses extensive BMP and PNG loading. Also the code that you are trying to load it with.

Here :D and the code is the SAME code as the OP, I just used my file instead, tried it with 0 and with 1 same thing.
if I make this into a GIF, it worked fine.



Title: Re: sprite_add not working?
Post by: Goombert on January 19, 2015, 11:10:25 pm
(http://i.imgur.com/KXD9wcC.jpg)

I don't know, I plugged it into my last Project Mario build and it seems to work fine. I can't build an exe right now because I have the 64 built configured right now but I haven't updated the libraries. An executable would be helpful.
Title: Re: sprite_add not working?
Post by: TheExDeus on January 20, 2015, 04:45:48 am
I just tested loading and drawing in my ENIGMA (which is very up to date and only few commits behind) and it's working fine:
(http://i.imgur.com/vfDdZS9.png)

Code:
Code: (edl) [Select]
spr = sprite_add("C:\001.png",1,0,0,0,0);
draw_sprite(spr,-1,mouse_x,mouse_y);

edit: I tested both  GL1 and GL3. Can you maybe try GDB and post the bt?
Title: Re: sprite_add not working?
Post by: RobotiX on January 20, 2015, 08:15:39 pm
Quote
It looks like we never actually even outlined the function. I can give you the basic steps to add it though.
First outline the function in the general header https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Audio_Systems/General/ASbasic.h#L62
it should be the same path in your local enigma-dev copy regardless of how you installed. By outlining it there it ensures the parameter and return types are the same for every system.
Then you just add the body of the function in https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Audio_Systems/DirectSound/DSbasic.cpp#L92
or https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Audio_Systems/OpenAL/ALbasic.cpp#L152
for OpenAL. That's really all you need to do and the function will be usable, you could also send us a pull request on GitHub and we may merge it so long as you write the code neatly to match the other functions in the files.

Are you suggesting I try writing the sound_fade function? I'd be interested to learn but I know very little about the inner workings of ENIGMA or OpenAL...
I guess you gotta start somewhere though...
Title: Re: sprite_add not working?
Post by: Goombert on January 22, 2015, 09:13:39 pm
Haha, no I was merely pointing out that it is really easy to add new functions, just like you would in your own self contained game or C++ program, it's extremely trivial.

On a side note I also managed to get the latest 32 bit branch working again with sorloks gif fixes and my 64 bit compiler fixes, and the image loaded fine for me from the working directory simply calling it "file.png"

So Darkstar2's version probably just got broken or out of sync somehow.

(http://i.imgur.com/Uywihrw.png)