Skip to content
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

Crash when setCacheEnabled(..) is set to true #14

Closed
braj008 opened this issue Aug 23, 2013 · 13 comments
Closed

Crash when setCacheEnabled(..) is set to true #14

braj008 opened this issue Aug 23, 2013 · 13 comments

Comments

@braj008
Copy link

braj008 commented Aug 23, 2013

When I load app with setCacheEnabled(..) to true, its crashing at below method

  private void addBitmapToMemoryCache( String key, Bitmap bitmap ) {        
    if ( getBitmapFromMemoryCache( key ) == null ) {
    // crashing here
        memoryCache.put( key, bitmap );
    }
}

Here, both key and bitmap are null. May be some null check should work.

@klattimer
Copy link

If you're seeing this you're probably getting out of memory errors first, if your app is memory intensive then you may want to try adding largeHeap to the android manifest. I had this problem caused by loading up an apk extension file which required the zip decompressor in memory, thus leading to an oom error and then to this.

I think a simple null check here would help too.

@braj008
Copy link
Author

braj008 commented Aug 23, 2013

I am sure it's not about OOM error. Logcat message clearly shows its a NullPointerException as below

08-23 13:08:22.172: E/AndroidRuntime(22880): FATAL EXCEPTION: AsyncTask
08-23 13:08:22.172: E/AndroidRuntime(22880): java.lang.RuntimeException: An error occured while executing doInBackground()
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.os.AsyncTask$3.done(AsyncTask.java:276)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.lang.Thread.run(Thread.java:856)
08-23 13:08:22.172: E/AndroidRuntime(22880): Caused by: java.lang.NullPointerException: key == null || value == null
08-23 13:08:22.172: E/AndroidRuntime(22880): at android.support.v4.util.LruCache.put(LruCache.java:117)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.tileview.tiles.TileCache.addBitmapToMemoryCache(TileCache.java:117)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.tileview.tiles.TileCache.addBitmap(TileCache.java:72)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.tileview.tiles.Tile.decode(Tile.java:75)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.tileview.tiles.TileManager.decodeIndividualTile(TileManager.java:308)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.tileview.tiles.TileRenderTask.doInBackground(TileRenderTask.java:51)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.tileview.tiles.TileRenderTask.doInBackground(TileRenderTask.java:1)
08-23 13:08:22.172: E/AndroidRuntime(22880): at com.qozix.os.AsyncTask$2.call(AsyncTask.java:262)
08-23 13:08:22.172: E/AndroidRuntime(22880): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-23 13:08:22.172: E/AndroidRuntime(22880): ... 4 more

@moagrius
Copy link
Owner

Thanks for the note - I'll take a look as soon as I have some time - I probably just missed something when migrating. If you find a fix before then please post.

@yolapop
Copy link

yolapop commented Aug 25, 2013

anyone found the fix?

Thx b4

@moagrius
Copy link
Owner

I just tried and am unable to reproduce - it works fine for me. I suspect there's probably a bad file request (perhaps the result over overly-aggressive intersection detection, which was slightly modified from the previous version).

If either of you @yolapop or @braj008 want to post a problem app somewhere, I'd be interested in taking a look / debugging - otherwise I'd suggest trying the null checks mentioned earlier:

private void addBitmapToMemoryCache( String key, Bitmap bitmap ) {        
    if ( key == null || bitmap == null ) {
        return;
    }
    if ( getBitmapFromMemoryCache( key ) == null ) {
    // crashing here
        memoryCache.put( key, bitmap );
    }

If that works, post back and I'll update the repo.

Thanks

@yolapop
Copy link

yolapop commented Aug 25, 2013

Worked for me 👯

@moagrius
Copy link
Owner

cool - I've committed the change as well. will leave issue open for a while in case anyone wants to post an app for debug

@braj008
Copy link
Author

braj008 commented Aug 26, 2013

Above mentioned solution is enough to solve the problem. I have been using following solution.

private void addBitmapToMemoryCache( String key, Bitmap bitmap ) {

    if ( getBitmapFromMemoryCache( key ) == null && bitmap != null ) {
        memoryCache.put( key, bitmap );
    }
} 

@Tristus1er
Copy link
Collaborator

I would better suggest this fix:

In: DetailLevel in getIntersections function:

Replace

        int startingRow = (int) Math.floor( viewport.top / offsetHeight );
        int endingRow = (int) Math.ceil( viewport.bottom / offsetHeight );
        int startingColumn = (int) Math.floor( viewport.left / offsetWidth );
        int endingColumn = (int) Math.ceil( viewport.right / offsetWidth );

By:

        int startingRow = (int) Math.floor( viewport.top / offsetHeight );
        int endingRow = (int) Math.ceil( viewport.bottom / offsetHeight ) - 1;
        int startingColumn = (int) Math.floor( viewport.left / offsetWidth );
        int endingColumn = (int) Math.ceil( viewport.right / offsetWidth ) - 1;

As tailes are from 0 to n

@moagrius
Copy link
Owner

awesome, big thanks - i'll try this out soon and if it works consistently i'll post a new commit

Tristus1er added a commit to Tristus1er/TileView that referenced this issue Aug 27, 2013
@braj008
Copy link
Author

braj008 commented Aug 27, 2013

@Tristus1er solution worked. Shall I close the issue?

@moagrius
Copy link
Owner

@braj008 i'll leave it open as a reminder until i test and commit the patch. thanks

@moagrius
Copy link
Owner

updated in the latest release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants