[0.13.15] Constant combinator control using unsigned count

This subforum contains all the issues which we already resolved.
Post Reply
GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

[0.13.15] Constant combinator control using unsigned count

Post by GotLag »

When saving ConstantCombinatorParameters via Lua, the count is converted to an unsigned int.

Given that you can manually set negative values in constant combinator GUIs, this is probably not correct behaviour.

Loewchen
Global Moderator
Global Moderator
Posts: 8360
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by Loewchen »

Please post a minimalistic example that shows this behaviour.

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by GotLag »

Ah, my mistake. It seems in my test case the error was being thrown when writing the combinator settings, but the erroneous values were coming from somewhere else.
Screenshot

I know it's not a minimal case but somewhere in the on_tick function in control.lua in this mod a signed integer is being converted to unsigned:
http://gozaima.su/factorio/bug/Wireless ... _0.2.0.zip

I can't seem to pin it down, I just know that as soon as I try to transmit a negative value I get the error in the screenshot, and the value printed there as "count" is equal to the negative value read as an unsigned integer.

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 300
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by justarandomgeek »

I don't have an example handy, but I know on more than one occasion while examining a decompressed blueprint I've gotten large-positive in constant combinator parameters where i should have gotten small-negative. Putting negative in when generating a print works just fine though. I'll see if I can get a proper example later today...

Loewchen
Global Moderator
Global Moderator
Posts: 8360
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by Loewchen »

Ok, Ill move this to Pending for now but will move it back once we can narrow it down some more.

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 300
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by justarandomgeek »

Okay, I just made a Constant Combinator, configured it to output signal-red=-1, and exported a blueprint.

I got the following print:

Code: Select all

H4sIAAAAAAAA/3WPwWrDMAyGXyX47EJbuo0Q9ArtIwQ11jqBIxVHCS3G776YpYceppNAnz7+P2gTdcDY9JB5UJkgZ5ZADzj4iW+CEbI97wSOjUbnBcd1r6Ch
2G7Q8cqCpsmVUjyJsTFVyf+gv+u0UiqQH7D3T9gXv3KWNPZX+sGFNUH+5miUquk9xsLJZoyvJH/HXaLgqmUWg9OxPbWfX8f2w29NSp3t4Uw3NF6ouQi50iWy
OUnTdyThFzH2sxUMAQAA
Which decompresses (`cat Negative\ One.blueprint | base64 -d | gunzip`) and re-indents to this:

Code: Select all

do local _={
  icons={{index=1,signal={type="item",name="constant-combinator"}}},
  entities={
    {
      name="constant-combinator",position={x=0,y=0},
      control_behavior={
        filters={{signal={type="virtual",name="signal-red"},count=4294967295,index=1}}
      }
    }
  },
  name="Negative One"
};
return _;
end
As you can see, the -1 became 4294967295, which is the unsigned interpretation of the same bits.

The game seems quite happy to load this back in with either value, both becoming -1, but it seems odd that it was converted improperly on export.

It's not entirely clear if this quirk is related to GotLag's bug or just a lua/serpent quirk, but at least it's now been described!

Loewchen
Global Moderator
Global Moderator
Posts: 8360
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by Loewchen »

justarandomgeek wrote:Okay, I just made a Constant Combinator, configured it to output signal-red=-1, and exported a blueprint.
I got the following print:

Code: Select all

H4sIAAAAAAAA/3WPwWrDMAyGXyX47EJbuo0Q9ArtIwQ11jqBIxVHCS3G776YpYceppNAnz7+P2gTdcDY9JB5UJkgZ5ZADzj4iW+CEbI97wSOjUbnBcd1r6Ch
2G7Q8cqCpsmVUjyJsTFVyf+gv+u0UiqQH7D3T9gXv3KWNPZX+sGFNUH+5miUquk9xsLJZoyvJH/HXaLgqmUWg9OxPbWfX8f2w29NSp3t4Uw3NF6ouQi50iWy
OUnTdyThFzH2sxUMAQAA
How did you get the BP exported?

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 300
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by justarandomgeek »

I used Foreman at git commit 2ba66b4, which should be equivalent for this purpose to the 0.2.4 version on the mod portal - the only differences are related to loading scripts on the import side. I haven't tested with Blueprint Strings, but it's the same library, so it should be the same.

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by GotLag »

http://gozaima.su/factorio/bug/Combinat ... _1.0.0.zip

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
  if event.created_entity.name == "constant-combinator" then
    local control = event.created_entity.get_or_create_control_behavior()
    local new_parameters =
    {
      parameters =
      {
        {
          signal =
          {
            type = "item",
            name = "iron-plate"
          },
          count = -1,
          index = 1
        }
      }
    }
    control.parameters = new_parameters
    game.players[event.player_index].print
    (
      new_parameters.parameters[1].count
      ..  ", " ..
      control.parameters.parameters[1].count
    )
  end
end)
Prints "-1, 4294967295" when building a constant combinator

Twinsen
Factorio Staff
Factorio Staff
Posts: 1330
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: [0.13.15] Constant combinator control using unsigned count

Post by Twinsen »

Right, this is caused by the constant combinator parameters being stored as uint32_t instead of int32_t due to a typo. And since C++ implicitly converts between the 2 types with no problems or warnings, no one noticed.

Unfortunately fixing it properly now will make blueprint strings with negative combinator parameters no longer work. So I'll fix it for 0.14

Post Reply

Return to “Resolved Problems and Bugs”