Skip to content

Commit

Permalink
fix: NPE resulting from wrong SourceInfo map
Browse files Browse the repository at this point in the history
* when createBigWarpData from Source arrays

see #182
  • Loading branch information
bogovicj committed Feb 10, 2025
1 parent 52031b4 commit 82a550f
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions src/main/java/bigwarp/BigWarpInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,44 +250,28 @@ private static ValuePair<ScaledARGBConverter.ARGB, ScaledARGBConverter.VolatileA
* @return BigWarpData the data
*/
@SuppressWarnings( { "rawtypes", "unchecked" } )
public static BigWarpData< ? > createBigWarpData( final Source< ? >[] movingSourceList, final Source< ? >[] fixedSourceList, final String[] names )
public static <T> BigWarpData< ? > createBigWarpData( final Source< ? >[] movingSourceList, final Source< ? >[] fixedSourceList, final String[] names )
{
final BigWarpData data = initData();
int nameIdx = 0;
int setupId = 0;

// moving
for ( final Source< ? > mvgSource : movingSourceList )
{
add( data, mvgSource, setupId, 1, true );
final SourceAndConverter< ? > addedSource = ( ( BigWarpData< ? > ) data ).sources.get( data.sources.size() - 1 );
final SourceInfo info = new SourceInfo( setupId, true, names[ nameIdx++ ] );
info.setSourceAndConverter( addedSource );
data.sourceInfos.put( setupId++, info );
}
for (final Source<?> mvgSource : movingSourceList)
add(data, createSources(data, (Source<T>) mvgSource, setupId++, true));

// target
for ( final Source< ? > fxdSource : fixedSourceList )
{
add( data, fxdSource, setupId, 1, false );
final SourceAndConverter< ? > addedSource = ( ( BigWarpData< ? > ) data ).sources.get( data.sources.size() - 1 );
final SourceInfo info = new SourceInfo( setupId, false, names[ nameIdx++ ] );
info.setSourceAndConverter( addedSource );
data.sourceInfos.put( setupId++, info );
}
for (final Source<?> fxdSource : fixedSourceList)
add(data, createSources(data, (Source<T>) fxdSource, setupId++, false));

if ( names != null )
{
final ArrayList wrappedSources = wrapSourcesAsRenamable( data.sources, names );
final AtomicInteger sourceInfoIdx = new AtomicInteger();
// set names
final ArrayList wrappedSources = wrapSourcesAsRenamable( data.sources, names );
final AtomicInteger sourceInfoIdx = new AtomicInteger();
data.sources = wrappedSources;

final BigWarpData< ? > typedData = data;
typedData.sourceInfos.forEach( ( id, info ) -> {
info.setSourceAndConverter( typedData.sources.get( sourceInfoIdx.getAndIncrement() ) );
} );

return new BigWarpData( wrappedSources, data.converterSetups, data.cache );

}
final BigWarpData< ? > typedData = data;
typedData.sourceInfos.forEach( ( id, info ) -> {
info.setSourceAndConverter( typedData.sources.get( sourceInfoIdx.getAndIncrement() ) );
} );

return data;
}
Expand Down

0 comments on commit 82a550f

Please sign in to comment.