Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Please, help me with lua crash — Gideros Forum

Please, help me with lua crash

unlyingunlying Guru
edited October 2015 in General questions
Hello
I have hundreds lua crashes in my game(may be games)
com.giderosmobile.android.player.LuaException: C:/export/sostavslovo/assets/assets/json.lua.jet:273: Nil string: ''
stack traceback:
	C:/export/sostavslovo/assets/assets/json.lua.jet:273: in function <C:/export/sostavslovo/assets/assets/json.lua.jet:269>
	(tail call): ?
	C:/export/sostavslovo/assets/assets/datasaver.lua.jet:56: in function 'loadValue'
	C:/export/sostavslovo/assets/assets/main.lua.jet:189: in main chunk
       at com.giderosmobile.android.player.GiderosApplication.throwLuaException(GiderosApplication.java:1013)
       at com.giderosmobile.android.player.GiderosApplication.nativeDrawFrame(GiderosApplication.java)
       at com.giderosmobile.android.player.GiderosApplication.onDrawFrame(GiderosApplication.java:557)
       at com.giderosmobile.android.GiderosRenderer.onDrawFrame(sostavslovoActivity.java:268)
       at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1542)
       at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1266)
189 row is a
data = dataSaver.loadValue("data")
I don't know what to do and why it happens.

Comments

  • piepie Member
    Maybe you are trying to load a value that doesn't exists or that is saved with a wrong syntax.

    A similar error happens to me when I update my savefile with some entry and I auto load a savefile generated with a previous release of the game.

    You could try removing data.json from |D| folder and let your game write a new one, or open it with text or json editor and check it for "strange" nil strings.
    You could also put a print () in datasaver to check which value is causing troubles

    :)
  • Is there any reason you are using json.lua instead of json plugin?
    It seems you are using quite old version of dataSaver.lua then.

    But yes, basically the problem is that you are passing empty string "" to json decode.

    The way dataSaver works is that it reads value and checks if it is nil, and if not try to decode it with json. And next time when you save the value it encodes it as json.

    So expected values are json string or nil, that dataSaver can handle.

    Somehow, for some reason, you have saved empty string instead of nil or json string and it stumbles on it :)
  • @pie
    Thanks. I can't open file or put "prints" because i don't have devices with that error. It happens on user devices.
  • @ar2rsawseen It is old app that uses json.lua for years. I don't know neither about new datasaver nor json plugin.
    Btw i'm pretty sure that i'm not saving any strings to "data". But i'm saving links that loads from web to another datasaver value.
    Anyway. If i'll use new datasaver(where can i get it?) and json plugin - will it help?
    Can i put some checks to prevent crashes?
  • new json is just libjson.so in Android and native json is available for any supported platform too.

    datasaver github repo contains datasaver which uses native json

    But I don't think it would solve the problem, unless we understand where the problem comes from.

    Maybe users modify files directly?

    One way to handle it is to use pcall to safely call function (it is like try and catch block in lua).
    local success, data = pcall(dataSaver.loadValue, "data")
     
    if success then
       --you can use value in data variable
    else
      --there was an error reading value
    end
  • There are hundreds crashes for few days. So it's not users fault.
    A way with pcall will cause losing all user progress. It is like uninstall and install.
  • jdbcjdbc Member
    edited October 2015
    You have a old datasaver.lua file with Json instead of json.

    Use json native plugin.
  • I also have the problem now
  • I found a problem finally. It was about crashes when app was trying to save data.
    I don't know why, but sometimes app crashes on:
    channel=erase:play(0,1)
    channel:setVolume(data.volum)
    Crashlog trying to say that there is no channel at all. So i made this:
    channel=erase:play(0,1)
    if channel then
    channel:setVolume(data.volum)
    end
    Yep, sometimes users will listen a sound when it should be off, but app will not crash.
  • Sometimes, mainly on Android I find, a sound channel is sometimes never created when running the play() method. So I do what you do and check that the channel isn't nil before using it.
    My Gideros games: www.totebo.com
  • It's always good to check these things for nil anyhow - even sprites, etc...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.