GM:S 1.4 Game Loading not working after game restart (GMFMODsimple.dll)

Discussion in 'Programming' started by JesterOC, Jun 27, 2016.

  1. JesterOC

    JesterOC Member

    Joined:
    Jun 27, 2016
    Posts:
    23
    So I'm making a game and I added GMFMODsimple.dll so i could use sound panning and such...

    I thought i had it all working... save works... load works from main menu and game over screen, restoring the sounds that were playing at the positions they were at...
    BUT it turns out that when you close the game and run it again you can't load the save files... The game just crashes... I havent used many DLLs in the past so i might've done something wrong...

    Here's the loading and saving code...

    Save case: (used in the open world farm/dungeon/town room)

    Code:
    case "NPC-Save":
    newroom = room
    playerroom = true
    ini_open("FarmConfig.kbinput")
    ini_write_string("Config","buttons",kbinputGetConfigString())
    ini_close()
    //do some audio stuff
    global.daysndpos = 0
    global.nightsndpos = 0
    global.daysndpos = FMODInstanceGetPosition(global.sndday);
    global.nightsndpos = FMODInstanceGetPosition(global.sndnight);
    global.sndpos = 0;
    global.sndpos2 = 0;
    if FMODInstanceIsPlaying(obj_fadein.snd) global.sndpos = FMODInstanceGetPosition(obj_fadein.snd)
    if FMODInstanceIsPlaying(obj_fadein.snd2) global.sndpos2 = FMODInstanceGetPosition(obj_fadein.snd2)
    audio_play_sound(snd_Saved,1,0);
    FMODAllStop()
    //FMODfree() //dont use here, sounds not working on load
    //UnloadFMOD()
    game_save("FarmSave.trumpet");
    FMODinit(1000,0); //was above save with 2/3 success loading
    //with SimpleSoundControlerObj {event_perform(ev_other,ev_user0)}
    //start up looping sounds ( because save doesn't keep sounds playing)
    if !FMODInstanceIsPlaying(global.sndday) { global.sndday = FMODSoundLoop(global.bkMusic,0)}
    if global.sndday == 0 {show_message(FMODErrorStr(FMODGetLastError()));}
    //checkif we need ro (re)set panning
    if global.players == 2 {
    if global.inside2 == 1 and global.inside1 == 0 {FMODInstanceSetPan(global.sndday,-1)}
    if global.inside1 == 1 and global.inside2 == 0 {FMODInstanceSetPan(global.sndday,1)}
    }
    //reset positioning
    FMODInstanceSetPosition(global.sndday,global.daysndpos)
    //play night bg
    if !FMODInstanceIsPlaying(global.sndnight) { global.sndnight = FMODSoundLoop(global.bkMusicNT,0)}
    if global.sndnight == 0 {show_message(FMODErrorStr(FMODGetLastError()));}
    //check if we need to (re)set panning (night time)
    if global.players == 2 {
    if global.inside2 == 1 and global.inside1 == 0 {FMODInstanceSetPan(global.sndnight,-1)}
    if global.inside1 == 1 and global.inside2 == 0 {FMODInstanceSetPan(global.sndnight,1)}
    }
    //reset positioning
    FMODInstanceSetPosition(global.sndnight,global.nightsndpos)
    //set day and night vol to zero to start with
    FMODInstanceSetVolume(global.sndday,0)
    FMODInstanceSetVolume(global.sndnight,0)
    //end save stuff
    with obj_fadein {
    if global.inside1 == 1{
    if !FMODInstanceIsPlaying(snd) {
    snd = FMODSoundLoop(global.playbgsnd1,0)
    //reset positioning
    FMODInstanceSetPosition(snd,global.sndpos)
    //volume
    FMODInstanceSetVolume(snd,0.6)
    if global.players == 2{FMODInstanceSetPan(snd,-1)}
    }
    
    }
    if global.inside2 == 1{
    if !FMODInstanceIsPlaying(snd2)
    {
    snd2 = FMODSoundLoop(global.playbgsnd2,0)
    //reset positioning
    FMODInstanceSetPosition(snd2,global.sndpos2)
    FMODInstanceSetVolume(snd2,0.6)
    if global.players == 2{FMODInstanceSetPan(snd2,1)}
    }
    
    }
    
    }
    break;
    Load code: (used in main menu and on game over screen)

    Code:
    if file_exists("FarmSave.trumpet")
    {
    str = ""
    var tmpstr = "verylongstr";
    if file_exists("FarmConfig.kbinput"){
    ini_open("FarmConfig.kbinput")
    str = ini_read_string("Config","buttons",tmpstr)
    ini_close()
    }
    kbinputInitialize(16);
    if str != "" {kbinputSetConfigString(str);}else{kbinputSetConfigString(tmpstr);}
    FMODAllStop()
    FMODfree()
    //UnloadFMOD()
    //FMODinit(1000,0); //testing 2
    game_load("FarmSave.trumpet")
    }
    I suppose how i load the DLL is of importance:
    i use this code in the first room,


    Code:
    //This guy is persistant. Only place it in the start room
    LoadFMOD();
    FMODinit(1000,0);
    
    // load sounds code excluded
    I then change the room to Main_menu and never return to the first room while the game is still running.

    If anyone could help me identify why the game will save/load fine, but crash on loading after the game is restart/closed, i would much appreciate it, i took a few weeks off and came back to it, but another 6 hrs later and i've made very little progress towards fixing it, i did find out that its when the game is restarted... but i couldn't figure out why...

    Thanks for any help you can give me, JesterOC.
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,320
    That's because game_save() and game_load() are simple core dumps that don't handle dynamically referenced resources such as DLL handles, and also go out of context if even the slightest change is made to the project. It's a total noob trap. You need to consider what properties constitute your game state, then write your own custom save/load system according to that knowledge.
     
  3. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,837
  4. JesterOC

    JesterOC Member

    Joined:
    Jun 27, 2016
    Posts:
    23
    Thanks for the info, i was kinda aware of this... i really don't wanna remake the save system though, there's alot of open world objects that can be destroyed which i don't wanna have to save and load...

    Not sure what you're getting at, i read the documentation to do with the scripts and it doesn't say anything about saving and loading...

    BTW, I fixed it without remaking the save system....
    I unload the dll before load/save and reload it after save.


    The original reason that wasn't working before was something to do with this code (with statement just wasn't called):

    with SimpleSoundControlerObj {event_perform(ev_other,ev_user0)}

    so i moved it from user0 to a script. now it works :D

     
  5. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,837
    You know I wrote that dll right? how is this
    Support Game Saving/Loading
    Not related to saving and loading?

    It tells you how to detect a game load and what you need to do when a game load is detected
     
  6. JesterOC

    JesterOC Member

    Joined:
    Jun 27, 2016
    Posts:
    23
    Sorry was tired and didn't notice that second one was a link... tired now too, so i could only kinda follow it... i'll prolly have to come back to it later and use that method instead of unloading before save everytime...

    GREAT WORK ON THE DLL BTW :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice