- // Same url but border is different - use the existing texture
- Data* data = new Data();
- data->hash = hash;
- data->url = url;
- data->croppedWidth = mCache[ index ]->croppedWidth;
- data->croppedHeight = mCache[ index ]->croppedHeight;
-
- data->textureSet = mCache[ index ]->textureSet;
-
- NPatchUtility::StretchRanges stretchRangesX;
- stretchRangesX.PushBack( Uint16Pair( border.left, ( (data->croppedWidth >= static_cast< unsigned int >( border.right )) ? data->croppedWidth - border.right : 0 ) ) );
-
- NPatchUtility::StretchRanges stretchRangesY;
- stretchRangesY.PushBack( Uint16Pair( border.top, ( (data->croppedHeight >= static_cast< unsigned int >( border.bottom )) ? data->croppedHeight - border.bottom : 0 ) ) );
-
- data->stretchPixelsX = stretchRangesX;
- data->stretchPixelsY = stretchRangesY;
- data->border = border;
-
- data->loadCompleted = mCache[ index ]->loadCompleted;
-
- mCache.PushBack( data );
-
- return mCache.Count(); // valid ids start from 1u
+ // If we only found LOAD_FAILED case, replace current data. We can reuse texture
+ if(infoPtr == nullptr || infoPtr->mData->GetLoadingState() != NPatchData::LoadingState::LOAD_COMPLETE)
+ {
+ infoPtr = &mCache[index];
+ }
+ }
+ // Still loading pixel buffer. We cannot reuse cached texture yet. Skip checking
+ else if(mCache[index].mData->GetLoadingState() == NPatchData::LoadingState::LOADING)
+ {
+ continue;
+ }
+ // if LOAD_FAILED, reuse this cached NPatchData, and try to load again.
+ else
+ {
+ if(infoPtr == nullptr)
+ {
+ infoPtr = &mCache[index];
+ }