Search in sources :

Example 1 with CrashReport

use of net.modificationstation.stationapi.api.util.exception.CrashReport in project StationAPI by ModificationStation.

the class SpriteAtlasTexture method upload.

public void upload(Data data) {
    this.spritesToLoad.clear();
    this.spritesToLoad.addAll(data.spriteIds);
    LOGGER.info("Created: {}x{}x{} {}-atlas", data.width, data.height, data.maxLevel, this.id);
    TextureUtil.allocate(this.getGlId(), data.maxLevel, data.width, data.height);
    this.clear();
    for (Sprite sprite : data.sprites) {
        this.sprites.put(sprite.getId(), sprite);
        try {
            sprite.upload();
        } catch (Throwable throwable) {
            CrashReport crashReport = CrashReport.create(throwable, "Stitching texture atlas");
            CrashReportSection crashReportSection = crashReport.addElement("Texture being stitched together");
            crashReportSection.add("Atlas path", this.id);
            crashReportSection.add("Sprite", sprite);
            throw new CrashException(crashReport);
        }
        if (!sprite.isAnimated())
            continue;
        this.animatedSprites.add(sprite);
    }
    spriteFinder = null;
}
Also used : CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection)

Example 2 with CrashReport

use of net.modificationstation.stationapi.api.util.exception.CrashReport in project StationAPI by ModificationStation.

the class SpriteAtlasTexture method stitch.

public Data stitch(TexturePack resourceManager, Stream<Identifier> idStream, Profiler profiler, int mipmapLevel) {
    int p;
    profiler.push("preparing");
    Set<Identifier> set = idStream.peek(identifier -> {
        if (identifier == null) {
            throw new IllegalArgumentException("Location cannot be null!");
        }
    }).collect(Collectors.toSet());
    int i = this.maxTextureSize;
    TextureStitcher textureStitcher = new TextureStitcher(i, i, mipmapLevel);
    int j = Integer.MAX_VALUE;
    int k = 1 << mipmapLevel;
    profiler.swap("extracting_frames");
    for (Sprite.Info info2 : this.loadSprites(resourceManager, set)) {
        j = Math.min(j, Math.min(info2.getWidth(), info2.getHeight()));
        int l = Math.min(Integer.lowestOneBit(info2.getWidth()), Integer.lowestOneBit(info2.getHeight()));
        if (l < k) {
            LOGGER.warn("Texture {} with size {}x{} limits mip level from {} to {}", info2.getId(), info2.getWidth(), info2.getHeight(), MathHelper.log2(k), MathHelper.log2(l));
            k = l;
        }
        textureStitcher.add(info2);
    }
    int m = Math.min(j, k);
    int n = MathHelper.log2(m);
    if (n < mipmapLevel) {
        LOGGER.warn("{}: dropping miplevel from {} to {}, because of minimum power of two: {}", this.id, mipmapLevel, n, m);
        p = n;
    } else {
        p = mipmapLevel;
    }
    profiler.swap("register");
    textureStitcher.add(MissingSprite.getMissingInfo());
    profiler.swap("stitching");
    try {
        textureStitcher.stitch();
    } catch (TextureStitcherCannotFitException textureStitcherCannotFitException) {
        CrashReport crashReport = CrashReport.create(textureStitcherCannotFitException, "Stitching");
        CrashReportSection crashReportSection = crashReport.addElement("Stitcher");
        crashReportSection.add("Sprites", textureStitcherCannotFitException.getSprites().stream().map(info -> String.format("%s[%dx%d]", info.getId(), info.getWidth(), info.getHeight())).collect(Collectors.joining(",")));
        crashReportSection.add("Max Texture Size", i);
        throw new CrashException(crashReport);
    }
    profiler.swap("loading");
    List<Sprite> list = this.loadSprites(resourceManager, textureStitcher, p);
    profiler.pop();
    return new Data(set, textureStitcher.getWidth(), textureStitcher.getHeight(), p, list);
}
Also used : ResourceManager(net.modificationstation.stationapi.api.resource.ResourceManager) CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection) java.awt.image(java.awt.image) java.util(java.util) MODID(net.modificationstation.stationapi.api.StationAPI.MODID) java.util.stream(java.util.stream) Environment(net.fabricmc.api.Environment) LOGGER(net.modificationstation.stationapi.impl.client.texture.StationRenderImpl.LOGGER) Resource(net.modificationstation.stationapi.api.client.resource.Resource) CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) Lists(com.google.common.collect.Lists) TexturePack(net.minecraft.client.resource.TexturePack) Identifier(net.modificationstation.stationapi.api.registry.Identifier) EnvType(net.fabricmc.api.EnvType) Util(net.modificationstation.stationapi.api.util.Util) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) ApiStatus(org.jetbrains.annotations.ApiStatus) java.util.concurrent(java.util.concurrent) javax.imageio(javax.imageio) Pair(com.mojang.datafixers.util.Pair) MathHelper(net.modificationstation.stationapi.api.util.math.MathHelper) AnimationResourceMetadata(net.modificationstation.stationapi.api.client.resource.metadata.AnimationResourceMetadata) Nullable(org.jetbrains.annotations.Nullable) java.io(java.io) Profiler(net.modificationstation.stationapi.api.util.profiler.Profiler) SpriteFinderImpl(net.modificationstation.stationapi.impl.client.render.SpriteFinderImpl) RenderSystem(net.modificationstation.stationapi.impl.client.texture.RenderSystem) CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection) Identifier(net.modificationstation.stationapi.api.registry.Identifier)

Example 3 with CrashReport

use of net.modificationstation.stationapi.api.util.exception.CrashReport in project StationAPI by ModificationStation.

the class PalettedContainer method lock.

public void lock() {
    if (this.writeLock.isLocked() && !this.writeLock.isHeldByCurrentThread()) {
        String string = Thread.getAllStackTraces().keySet().stream().filter(Objects::nonNull).map((thread) -> thread.getName() + ": \n\tat " + Arrays.stream(thread.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n\tat "))).collect(Collectors.joining("\n"));
        CrashReport crashReport = new CrashReport("Writing into PalettedContainer from multiple threads", new IllegalStateException());
        CrashReportSection crashReportSection = crashReport.addElement("Thread dumps");
        crashReportSection.add("Thread dumps", string);
        throw new CrashException(crashReport);
    } else {
        this.writeLock.lock();
    }
}
Also used : CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection) java.util(java.util) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) CompoundTag(net.minecraft.util.io.CompoundTag) LongArrayCompound(net.modificationstation.stationapi.impl.nbt.LongArrayCompound) java.util.stream(java.util.stream) Environment(net.fabricmc.api.Environment) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) PackedIntegerArray(net.modificationstation.stationapi.api.util.collection.PackedIntegerArray) MathHelper(net.modificationstation.stationapi.api.util.math.MathHelper) java.util.concurrent.locks(java.util.concurrent.locks) CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) Message(net.modificationstation.stationapi.api.packet.Message) EnvType(net.fabricmc.api.EnvType) java.util.function(java.util.function) ListTag(net.minecraft.util.io.ListTag) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) IdList(net.modificationstation.stationapi.api.util.collection.IdList) CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection)

Aggregations

CrashException (net.modificationstation.stationapi.api.util.exception.CrashException)3 CrashReport (net.modificationstation.stationapi.api.util.exception.CrashReport)3 CrashReportSection (net.modificationstation.stationapi.api.util.exception.CrashReportSection)3 java.util (java.util)2 java.util.stream (java.util.stream)2 EnvType (net.fabricmc.api.EnvType)2 Environment (net.fabricmc.api.Environment)2 MathHelper (net.modificationstation.stationapi.api.util.math.MathHelper)2 Lists (com.google.common.collect.Lists)1 Pair (com.mojang.datafixers.util.Pair)1 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 java.awt.image (java.awt.image)1 java.io (java.io)1 java.util.concurrent (java.util.concurrent)1 java.util.concurrent.locks (java.util.concurrent.locks)1 java.util.function (java.util.function)1 javax.imageio (javax.imageio)1 TexturePack (net.minecraft.client.resource.TexturePack)1 CompoundTag (net.minecraft.util.io.CompoundTag)1