-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read field "entity" because "c" is null #548
Comments
Can’t reproduce, please test patch G. |
@TropheusJ I can confirm the bug is still happening on patches 0.5.0g-791 and 0.5.0g-796. The steps for replication for how I encountered the error are as follows:
Expected Result: The contraption is created successfully Actual Result: The game hard crashes to the desktop with the error message 'Cannot read field "entity" because "c" is null' |
As a follow-up, I looked into the code surrounding this area and please correct me if I am wrong, but I think this might be a race condition with the renderer and the assembly of the offending contraption. Consider the following: The code that is erroring out is this line in the ContraptionRenderingWorld.java file:
when we call getRenderInfo() it performs this action which results in a null reference exception:
Specifically, We can conclude that the entity is getting initialized and added to the world because if it was null then the
Then on line 130 it gets assembled.
Finally, after it is assembled, some more actions are performed finally, on line 161 the entity is created.
When the OrientedContraptionEntity.create() call is executed, the entity.setContraption() method is called almost immediately and inside that the onEntityCreated() call is executed if the contraption is not null, which we know it is initialized and therefore not null, and if the level is not clientside, which I cannot confirm. If we assume that the level is not client side, then the onEntityCreated() method is called and the contraption should be successfully assigned to the entity and there should be no null reference exception, but this is not what is happening. The gap in my knowledge right now, is that I am unsure how the entity gets registered within the world. If it works how I suspect, being that as soon as an entity is created it is registered in the world, it would mean that if the render tick is happening too fast then its possible to get an entity with no related contraption because it is still being constructed/assigned. I am not a Minecraft mod developer, nor a java developer, but I have spent the last 10 years debugging code and fixing difficult bugs including race conditions and this has all the tell tale signs of a race condition. As a fix, I suggest someone who is set up to debug and test this simply adds a filter before the forEach loop that filters out entities with null contraptions as they have not yet been initialized and therefore are not ready to render. Again though, I am not a Minecraft mod developer, and my experience solely comes from my time as a software developer and I made a whole bunch of assumption here. Feel free to correct me, I just really want to build my giant-ass world eater without my world crashing and forcing me to go into the NBT data to delete the offending entity so I thought I would lend an external view to the problem as it seems this has been going on for a while. |
This has been a weird recurring issue that seems to be persistent for some people, but I've never been able to reproduce it. A race condition is probably the cause at this point. |
@TropheusJ I can also replicate it on Forge. I switched to Fabric, hoping it wouldn't continue, but I was wrong. |
In that case, it should be fixed on forge and then pulled into fabric. If you can get it to happen on forge again, report it there. |
@TropheusJ I can do that, I will copy my response over to the relevant open issue, |
I had this occur on a server and I think I've tracked down the cause. If you install XL Packets is it fixed? |
@TropheusJ you absolute GENIUS. Yes that fixed it. What is the source of the bug? Is it not a race condition? Also installing that packets mod greatly increased the performance of my world so thanks for that was well. |
Is there an issue on the Forge repo about this? |
PR is still waiting but a fix for the crash has been added |
Describe the Bug
On a server, whenever someone loads a certain area of the world (probably where the problem entity is located), every single person's game crashes, resulting from the Exception being thrown.
Reproduction Steps
We are not quite sure how to replicate this error, as it has happened multiple times now unexpectidly.
Expected Result
Game should not throw exception and crash for every single player online.
Screenshots and Videos
Crash Report or Log
https://pastebin.com/mGy1w3Mu
Operating System
Windows 11
Mod Version
0.5.0d
Minecraft Version
1.18.2
Other Mods
https://pastebin.com/zBbV0EaM
Additional Context
The issue seems to be able to be resolved by killing all entities when the player close enough to the problematic entity loads into the world.
This crash also occured on patch 0.5.0c
The text was updated successfully, but these errors were encountered: