Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Lua Crash Reports - Request — Gideros Forum

Lua Crash Reports - Request

adityaaditya Member
edited February 2014 in Suggestions & requests
Currently beta testing with a couple of crashes, using crashlytics on iOS devices and the plugin by @bowerandy. For android, all we can do is physically test on devices and hope for the best. :P

Lua crash reports for both iOS and android would be great. If we could know the line of the code in lua which triggered the crash, it would mean the developers being able to see and fix their games/apps faster and more quality products being made with gideros... :)
Loon Games LinkedIn Facebook Twitter - "Something bit me, gaah!"

Comments

  • No not exactly, if it will work, it most probably will work on all reporting services :)
  • just wanted to share,

    we used crashlytics on android. we implemented it without plugins (too lazy) and just coded it in the main activity something like this :
            ReadThread thread;
    	private boolean is_lua_crash = false;
     
    	public void startRecordingLogs()
    	{
    		if(thread == null || !thread.isAlive())
    		{
    			thread = new ReadThread();
    			thread.start();
    		}
    	}
     
    	public void stopRecordingLogs()
    	{
    		thread.stopLogging();		
    	}
     
    	private class ReadThread extends Thread{
     
    		Process process;
    		Object lockObject = new Object();
    		FileOutputStream fos;
     
    		public ReadThread() {
    			try {
    				fos = openFileOutput("log.txt", MODE_PRIVATE);
    			} catch (FileNotFoundException e1) {
    				e1.printStackTrace();
    			}
    		}
     
    		public void run(){
    			String str_stack = "stack";
    			synchronized(lockObject)
    			{
    				try {
    					process = Runtime.getRuntime().exec("logcat Gideros:D *:S");        
     
    					BufferedReader reader = new BufferedReader(new InputStreamReader (process.getInputStream()));
    					String line;	      
    					while ((line = reader.readLine()) != null)
    					{
    						//while logging, check for any stack keyword, if it is that means we have a lua error
    						if(line.indexOf(str_stack) > -1) 
    							is_lua_crash = true;
    						fos.write((line + '\n').getBytes());			
    					}
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}	    
    		}
     
    		public void stopLogging()
    		{
    			process.destroy();			
    		}
    	}
    	//------------------------
    and then on destroy
    public void onDestroy()
    	{
    		GiderosApplication.onDestroy();
    		super.onDestroy();
     
    		// crashlytics -----
    		try {
    			// delete all old logcat output
    			try {
    				Runtime.getRuntime().exec("logcat -c");
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
     
    			if(is_lua_crash) {
    				FileInputStream fis = openFileInput("log.txt");
    				Scanner scanner = new Scanner(fis);
    				String content = null;
    				scanner.useDelimiter("\\Z");
    				if(scanner.hasNext()) {
    					content = scanner.next();
    				}					
    				scanner.close();
     
    				if(content != null)
    					throw new RuntimeException(content);	
    			}
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		// ----------------
    	}
    The above code is not complete but it should give you a general idea. You'll also need to set things in manifest such as permission to be able to read logs.
  • VenorcisVenorcis Member
    edited February 2014
    I've also successfully got Crashlytics working with LUA stacktraces on iOS using @bowerandy's plug-in, and we would also love to get this working on Android.

    @bysreg Nice example; however you say that this is not complete and that I need to set 'things' in my manifest to make it work. Could you perhaps extend/complete this example so I'm sure I'm doing the right thing in my Android app?

    @ar2rsawseen What do you think about this example, is it useable in production?
  • @Venorcis, It's usable in production. I have used it in my game. well, sort of. in onDestroy, the above code force runtimeexception whenever there's a lua error (hinted by the stack keyword in the log) and then crashlytics logged the log.txt. The problem is, crashlytics wont differentiate the crashes. It categorizes all the runtimeexception into one category of crash. You can see the details of each of the crashes (by clicking more details) but as a result, you will be clicking the left arrow many times.

    I guess it's easy. The 'things' that i mention was of the crashlytics setup of which will be automatically added (to your activity and your manifest) by the crashlytic eclipse plugin. And also, to be able to record the log, you need to add read logs permission on your android manifest
  • amaximovamaximov Member
    edited March 2014
    @Venorcis thanks for all that code! I managed to integrate it into my Android app and have already gotten a couple useful Lua crash reports. However I did not add READ_LOG permission and it is working fine but I have only received reports from rooted devices.

    Besides, Android docs say that permission is only for rooted devices:

    http://developer.android.com/reference/android/Manifest.permission.html

    However, one of the answers here says that this permission was depreciated, and now we don't need it but we can only see logs from OUR application.

    http://stackoverflow.com/questions/14201152/logcat-displays-nothing-when-used-from-runtime-exec

    Can anyone confirm this?
  • @amaximov I did add the permission, just to be sure, but to my knowledge it is indeed not necessary for newer devices anymore (from a certain Android version). It works anyway though; no harm done :)
Sign In or Register to comment.