Guidebook

Guidebook

6M Downloads

Stack bounds NPE

QbDesu opened this issue ยท 3 comments

commented

I can't seem to reliably reproduce it and it doesn't seem consistent at all but sometimes (really really rarely) when clicking a stack it causes a null pointer exception which causes a crash.
It only happened to me on linked stacks so far but that shouldn't actually make a difference because it should also call the method on not-linked stacks.

I am saying it's because of stack bounds because it happens on line 317 of BookRendering:

        Rectangle b = l.getBounds();
        if (mX >= b.getX() && mX <= (b.getX() + b.getWidth()) &&        //<- this line
                mY >= b.getY() && mY <= (b.getY() + b.getHeight()))

I have not yet been able properly track it down and step through it while it happened. I have a crash report for you but that doesn't actually say anything that I haven't said already (i think).

commented

I think due to the HUGE internal changes of v2.0 (beta), this issue may be fixed. I'll close this now, but feel free to verify and I'll reopen if it isn't.
https://minecraft.curseforge.com/projects/guidebook/files/2518170

commented

If this still occurs, it's simply because Stack.bounds is not initialized until it gets rendered in apply(), so somehow getBounds() is called before apply(...). To fix this, make a PR and either add an inline initializer when bounds is declared (which is called in the constructor automatically) or manually add in a default initialization line inside of the constructor.

commented

That's what I was so surprised about. I was able to click it while it was visible but when I clicked it caused this error even though apply should already have been called. I don't know if templates cause this funny behavior or not though.
I am aware that having a default initialization would fix it but it's just weird to me that it even occurred in the first place.