-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed application crash issue due to NullPointerException on exit #206
base: master
Are you sure you want to change the base?
Conversation
try { | ||
predictions = tlModel.predict(rgbImage, modelImageSize, modelImageSize); | ||
} | ||
catch (Exception e){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Could you specifically catch
NullPointerException
instead? It would be bad to catch all exceptions and ignore them in case something else happens. - Also, please add a comment explaining why the
NullPointerException
can be thrown and why we are ignoring it.
Thanks for your contribution!
@yyoon Thanks for reviewing my PR. First I would like to answer your second question.
As you can see here, in the
For some reason(I am searching)
The exact exception thrown is this,
I have logged the sequence of method calls as show below. You can see that last request for prediction is after completion of
Now coming to the first question.
Yes sure. I can handle |
Catching a NullPointerException is probably not what we want, we should either add a proper lock for inference or do the closing on the worker thread rather than the UI thread. |
There is an issue when application is closed.
tlModel
is set to null inonDestroy()
butInferenceThread
still callstlModel.predict
method without checking a null.java.lang.NullPointerException
is thrown at this line. Solved it using try-catch.