Prevent Game Crash

Posted By: msmith2468

Prevent Game Crash - 03/13/12 18:02

I am finishing up my game team effort. The problem I have is when a player exports a level. Exporting a level creates a file and writes to it. It works great as long as the player is running the game as an administrator however if they are not then the game crashes. I have placed warnings in the game that inform the player that they need to run the game as an administrator in order to export a level.

If there is a way I would like to prevent the crash. Is there a way that I can check to see if the user is running the game as the administrator or not? That way I could check before creating the new file and prevent the crash.

Or perhaps there is another fail safe method I could use. I am open to suggestions Thanks.
Posted By: Ch40zzC0d3r

Re: Prevent Game Crash - 03/13/12 18:34

Where do you write the file?
Posted By: dice

Re: Prevent Game Crash - 03/13/12 19:00

I have the same problem with saving my game. I could'nt find a solution till now.

But I don't think that you can check the administrator mode from inside the game. More or less you have to assure the game is installed to start with admin rights. But I also dont know how to do this wink
Posted By: Rei_Ayanami

Re: Prevent Game Crash - 03/13/12 19:14

Are you saving to %appdata% or something (or directly in ProgramData)?
Posted By: fogman

Re: Prevent Game Crash - 03/13/12 19:35

Topic: Can 3dgs read from and write to %appdata%?
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=334501&an=

Go for it wink
Posted By: EvilSOB

Re: Prevent Game Crash - 03/13/12 19:37

Hows about this? It is just an idea, so you will need to test yourself.

Once you are about to do the save, try opening and closing a dummy file with
the EXACT same path and filename, but use the function FILE_OPEN_WRITE().
If it SUCESSFULLY opens (ie returns NOT zero), then you have the rights.
If it FAILS (ie returns a zero), then you are unable to save here(not admin?).

Im just not sure if this will trigger a windows error/warning if you are not admin.

Also beware, you may need to delete the dummy file(file_delete) before you actually save.
And when doing this make DOUBLY sure you give file_open_write the COMPLETE file-path.
Posted By: msmith2468

Re: Prevent Game Crash - 03/13/12 19:47

Thanks for the reply's

I create and write the files into the same folder that the game is in. If the player downloaded the zipped folder then they can place it anywhere they want. If the player downloaded the installer and had the game installed to their computer under the default settings then a folder is created in program files and that is where the exported level files would be saved to.

You got me thinking and I ran some tests. I found that the error only occurs in the installed version of the game and not the zipped folder. So I took the zipped folder and moved it to the same location as the installed version in program files. Just creating the new folder I had to give permission. And sure enough the error occurred.

So clearly the problem is with the location of the folder. That still leaves me with a problem. I could simply warn the user with a message and save the game before I even attempt to export the files.

Something like this maybe "If Exporting a level crashes the game then run the game as an administrator."
If anyone knows a way to fix this or to at least prevent the crash please let me know. Thanks again.

@dice
My problem is that my game exports a game level so that the user can send it to friends or save it. This requires me to create a new file with a unique name based on the level. This is where the error occurs when I create a new file. I have no problem writing or reading a file.

My point is that your game (I assume) creates a file based on the players name to store the save data. If you create one save file then store all of the data in that save file then you could avoid the error. I hope this helps.
Posted By: msmith2468

Re: Prevent Game Crash - 03/13/12 20:08

@dice
Sorry I assumed wrong. The crash happens anytime a file is written to not just file creation. I can read from a file without a problem.

@EvilSOB
I tested your suggestion and it worked. That's exactly what I was looking for. I am going to implement it so that when the game first starts up it checks if it can write to a file. If it can not then I will display a message that tells the user they must restart the game with administrator rights.

Thanks a lot everyone I appreciate it.
Posted By: MasterQ32

Re: Prevent Game Crash - 03/14/12 07:31

i think you can also use reis method: store your files into the appdata folder. every user can read/write into it without any problems
this should solve the problem in a nicer way...
Posted By: fogman

Re: Prevent Game Crash - 03/14/12 08:14

Manual says:
Quote:

Saving files into the program folder requires administrator rights under Windows Vista and above, and is thus not recommended. Use this string to set a different folder, f.i. in the ProgramData directory.


http://www.conitec.net/beta/asave_dir.htm
© 2024 lite-C Forums