Page 1 of 3 123 LastLast
Results 1 to 15 of 38

Thread: Fix for NullReferenceException [...] at TileEntityPoweredTrigger.write

  1. #1
    Tracker djkrose's Avatar
    Join Date
    Apr 2014
    Posts
    157
    Rep Power
    1

    Fix for NullReferenceException [...] at TileEntityPoweredTrigger.write

    Hi all,

    Like many others [1 2 3 4 5] I also get this server error in multiple locations:

    Code:
    NullReferenceException: Object reference not set to an instance of an object
      at TileEntityPoweredTrigger.write (System.IO.BinaryWriter _bw, StreamModeWrite _eStreamMode) [0x00000] in <filename unknown>:0 
      at Chunk.ZOU (System.IO.BinaryWriter , Boolean ) [0x00000] in <filename unknown>:0 
      at Chunk.write (System.IO.BinaryWriter stream) [0x00000] in <filename unknown>:0 
      at NetPackageChunk..ctor (.Chunk _chunk) [0x00000] in <filename unknown>:0 
      at ChunkManager.SendChunksToClients () [0x00000] in <filename unknown>:0 
      at GameManager.WU () [0x00000] in <filename unknown>:0 
      at GameManager.Update () [0x00000] in <filename unknown>:0
    • The message is continously spammed in the logfile while somebody is near the location.
    • People who log in to that area are stuck on the loading screen.
    • During this all other players receive heavy lag.


    Now, I can't complain because I'm running a 900 day old server with mods. - But thanks to debugging I could analyze the cause of the problem and write a fix for it.

    Internal Technical Details
    Spoiler: 
    The error caused by a corrupt power trigger, like a tripwire or power relay, that has the wrong PowerInfo object attached to it. With tripwires for example, the server wants to send the electricity data to the client but fails because of this piece of code in TileEntityPoweredTrigger.write(..):
    Code:
            PowerTripWireRelay powerItem = this.PowerItem as PowerTripWireRelay;
            _bw.Write(powerItem.Parent != null && powerItem.Parent is PowerTripWireRelay);
    The red part fails with NullReferenceException if this.PowerItem is something else than PowerTripWireRelay.

    I still don't know if the reason for the wrong object is an old map, or if parts of the current game actually still set the bad object. Maybe The Fun Pimps can figure that out with my information.

    Fixing the corrupt chunks

    I implemented a fix command to my ScriptingMod that scans all loaded chunks for corrupt power triggers and (optionally) fixes them. I've just applied the fix on my own server, and the problem is gone.

    Download ScriptingMod

    Activate automatic fixing of broken power blocks: dj-repair p /auto
    See for details: help dj-repair

    .oO( djkrose )Oo.
    Last edited by djkrose; 09-01-2017 at 02:28 PM. Reason: adjusted for new command release

  2. #2
    Tracker
    Join Date
    Feb 2017
    Posts
    174
    Rep Power
    0
    have you tested it on a16.2 exp? maybe fixed

    RWG hub cell pregen blocks spawning the player and chunks until finished
    RWG hub cell download blocks spawning the player and chunks until finished

  3. #3
    Tracker mythan's Avatar
    Join Date
    Jan 2015
    Location
    http://oz.nz
    Posts
    237
    Rep Power
    0
    How....has no one commented on this yet? This is absolutely amazing work. I also posted a bug report on this a couple of weeks ago:
    https://7daystodie.com/forums/showth...l=1#post697766

    I'm already running Alloc's, Bad Company and Coppi's mod.. but I'd happily add a fourth if it means we can unban electricity on our server and as long as it's compatible with those API mods.

    Our players will be delighted and I'll make sure to give you credit

    Edit: lol... ok, one comment beat me within the same minute.

  4. #4
    Scavenger
    Join Date
    May 2017
    Posts
    30
    Rep Power
    0
    Great work DJKrose, here's hoping you get some brownie points

  5. #5
    Tracker djkrose's Avatar
    Join Date
    Apr 2014
    Posts
    157
    Rep Power
    1
    Quote Originally Posted by kamer1337 View Post
    have you tested it on a16.2 exp? maybe fixed
    RWG hub cell pregen blocks spawning the player and chunks until finished
    RWG hub cell download blocks spawning the player and chunks until finished
    I just checked:
    The corresponding two code lines are still the same in A16.2 b7

    It could very well be that at other code places the origin of wrong tripwire PowerItems is fixed, but at least with existing maps with existing broken trip wires the problem will still occur.

    Just to be clear again: There is not necesseraly a bug in 7DTD code; it could still be caused by old maps or bad mods. The above mentioned two code lines just expect the right data and fail with bad data.

    djk

  6. #6
    QA Lead
    Join Date
    May 2014
    Posts
    479
    Rep Power
    1
    Hey djkrose!

    Thanks for your work on the issue so far!

    It would help us alot, if there was a video, by anyone really, on how to get this issue to appear in the first place.

    The savegames we had available to look at the timer relay was the problem, not the tripwire.

  7. #7
    Tracker djkrose's Avatar
    Join Date
    Apr 2014
    Posts
    157
    Rep Power
    1
    Quote Originally Posted by Hated View Post
    The savegames we had available to look at the timer relay was the problem, not the tripwire.
    While in my case it was the trip wire, in other cases it can definitely also be the timer rely, as the very next code command does the same assumption with timer relays: Assuming the PowerItem is a PowerTimerRelay, when in some corrupted map it probably isn't.

    [... analysis removed ...]




    Edit:

    Upon further inspection of the client-server communication I have to correct myself: What looked a bit strange at first is actually a clever way to put different parameters of different PowerItems into the same variables during transport. reads and writes match up.

    In short: I don't see a cause of corruption there anymore, and I still have no idea where the corrupt data is created. It just fails there because of corrupt data, which is ok.

    -djk-

    ps: The fix command to correct the data corruption still works. You can schedule it to run every few minutes if you want to.
    Last edited by djkrose; 08-05-2017 at 02:23 PM.

  8. #8
    Guppycurian Forum Whore Guppycur's Avatar
    Join Date
    Apr 2014
    Location
    Houston-ish, Texas
    Posts
    17,990
    Rep Power
    1
    Your disclaimer will likely get ignored...

  9. #9
    Survivor
    Join Date
    Feb 2016
    Posts
    95
    Rep Power
    0
    yeah so, this totally worked.

    Thanks.

  10. #10
    Tracker mythan's Avatar
    Join Date
    Jan 2015
    Location
    http://oz.nz
    Posts
    237
    Rep Power
    0
    djkrose, are you able to extend the fix to include the "PowerTimerRelay"? That's the one we had on our map.

    Would be awesome, thanks

  11. #11
    Tracker djkrose's Avatar
    Join Date
    Apr 2014
    Posts
    157
    Rep Power
    1
    Quote Originally Posted by mythan View Post
    djkrose, are you able to extend the fix to include the "PowerTimerRelay"? That's the one we had on our map.

    Would be awesome, thanks
    Already done. The new version will correct all PowerTiggers:

    Code:
                { PowerTrigger.TriggerTypes.Switch,        typeof(PowerTrigger) },
                { PowerTrigger.TriggerTypes.PressurePlate, typeof(PowerPressurePlate) },
                { PowerTrigger.TriggerTypes.TimerRelay,    typeof(PowerTimerRelay) },
                { PowerTrigger.TriggerTypes.Motion,        typeof(PowerTrigger) },
                { PowerTrigger.TriggerTypes.TripWire,      typeof(PowerTripWireRelay) }
    I just haven't released it yet because I broke the import/export commands in the process. :-\
    Will release it today I guess. Stay tuned...

  12. #12
    Tracker djkrose's Avatar
    Join Date
    Apr 2014
    Posts
    157
    Rep Power
    1
    Here you go, new release:
    https://github.com/djkrose/7DTD-ScriptingMod/releases

    Version 0.6 - tested with 7DTD A16.2 (b7)

    • Updated compatibility to 7DTD A16.2 (b7)
    • Fixed a bug where permissions for script commands could not be set
    • Extended dj-check-tripwires to repair ALL power triggers: Switch, PressurePlate, TimerRelay, Motion, TripWire
    • Renamed dj-check-tripwires to dj-check-power to reflect the broader usecase
    • Added command dj-pos to show exended informaton about current player's position
    • Added error checks on all commands

  13. #13
    Reconstructionist Drawfox's Avatar
    Join Date
    Aug 2014
    Posts
    585
    Rep Power
    0
    Sorry, I downloaded, but have no idea on how to run it, couldn't find any instruction. Could you help me, please?

  14. #14
    Scavenger
    Join Date
    Jul 2015
    Posts
    54
    Rep Power
    0
    Quote Originally Posted by Drawfox View Post
    Sorry, I downloaded, but have no idea on how to run it, couldn't find any instruction. Could you help me, please?
    Hey mate, given its a Mod, what I assume you would do is install it as such.
    In your game server, the root folder needs a "Mods" folder. (If you haven't installed any mods before this folder will not be there).

    If you extract this zip, you'll have a "Mods" folder, with the sub-folder under it that is this mod.

    So, in whatever way, have the Mods folder with this mod under it in your 7 days to die server folder.

    Then start your server.
    I assume the commands listed above are then available to be run from the console in game, or from telnet.
    Last edited by Dracknar; 08-06-2017 at 12:03 AM. Reason: More info

  15. #15
    Reconstructionist Drawfox's Avatar
    Join Date
    Aug 2014
    Posts
    585
    Rep Power
    0
    Hi Drack,
    Yeah, seems that I'm just running a server using the same version I use to play, so it won't work (I use the "startdedicatedserver.bat" from the game folder).
    I have no idea where I download the server version;
    Good news is, I could load my game on the "continue game" option, destruct my tripwire, and quit the game. That fixed my save.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •