readium-js icon indicating copy to clipboard operation
readium-js copied to clipboard

Resource cache (Blob URIs) algorithm incorrect: downshiftedEntry.orderingByLastUseTimestampIdx

Open danielweck opened this issue 10 years ago • 3 comments

Cloud reader, Chrome web browser, on Windows 8.1

To reproduce, navigate (using the TOC) several pages / spine items in SmokeTestFXL.

"algorithm incorrect: downshiftedEntry.orderingByLastUseTimestampIdx"

This assertion error occurs when ResourceCache.getResourceURL() is invoked.

https://github.com/readium/readium-js/blob/master/epub-modules/epub-fetch/src/models/resource_cache.js#L68

            function removeCacheEntryFromOrderedIndex(cacheEntry) {
                // Remove the previous entry from the ordered index, if present:
                if (typeof cacheEntry.orderingByLastUseTimestampIdx !== 'undefined') {
                    var orderingByLastUseTimestampIdx = cacheEntry.orderingByLastUseTimestampIdx;
                    _orderingByLastUseTimestamp.splice(orderingByLastUseTimestampIdx, 1);
                    // Decrement index values for all downshifted entries:
                    for (var i = orderingByLastUseTimestampIdx; i < _orderingByLastUseTimestamp.length; i++) {
                        var downshiftedEntry = _orderingByLastUseTimestamp[i];
                        // Assertion
                        if ((downshiftedEntry.orderingByLastUseTimestampIdx - 1) != i) {
                            console.error('algorithm incorrect: downshiftedEntry.orderingByLastUseTimestampIdx: ' +
                                downshiftedEntry.orderingByLastUseTimestampIdx + ', i: ' + i);
                        }
                        downshiftedEntry.orderingByLastUseTimestampIdx = i;
                    }
                }
            }

danielweck avatar May 20 '15 14:05 danielweck

Note: Blob URIs are used to populate linked resources in parsed HTML spine items and CSS files, only in the case of "programmatic fetching" (i.e. direct zipped EPUB loading, or obfuscated fonts in expanded EPUBs).

danielweck avatar May 20 '15 14:05 danielweck

I wonder if this has anything to do with premature _publicationResourcesCache.unPinResources() in a two-page synthetic spread (fixed layout => 2x spine items):

https://github.com/readium/readium-js/blob/develop/epub-modules/epub-fetch/src/models/publication_fetcher.js#L131

danielweck avatar May 20 '15 14:05 danielweck

+1

friedolinfoerder avatar Jun 03 '16 08:06 friedolinfoerder