Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Eunomiac

[OC 1.3] component.setPrimary() Not Working?

Question

Apologies for the kinda-double post, but the problem I initially described in "[OC 1.3] Inconsistent autorun.lua" seems to be something else entirely---which I only realized after several walls of text ;)

 

Hardware:  One computer, containing 3x GPU and 1x Hard Drive, linked by Cable to 3x Screens:

  • the "Terminal" --- a simple 1x1 with a keyboard
  • two "Displays" --- each is a large multiblock screen on the far side of the room

Software:  An autorun.lua file on the hard drive attempts to:

  1. mount the hard drive,
  2. set a specific GPU to be the primary GPU, then
  3. bind the primary GPU to the "Terminal" screen

Here's the full autorun.lua file (with a debug function edited out; "db(<string>)" simply logs the message to a debug file):

  local primaryGPUAddr = "3f5"
  local primaryScreenAddr = "1a1"
  local fs = require("filesystem")
  local component = require("component")

-- 1) MOUNT HARD DRIVE & VERIFY SUCCESS
  local address = ...
  local hdCheck, hdError = fs.mount(address, "/main")
  if hdCheck then
    db("1) Mounted hard drive under '/main'")
  else
    db("1) Hard Drive did NOT mount: " .. tostring(hdError))
  end

-- 2) SET PRIMARY GPU
-- (a) Checks address of randomly-chosen primary GPU:
  if component.isAvailable("gpu") then
    db("2(a) Primary GPU exists at Boot: " .. tostring(component.gpu.address))
  end

-- ( Change primary GPU:
  primaryGPUAddr = component.get(primaryGPUAddr) -- resolve full GPU address
  db("2( Setting Primary GPU to: " .. tostring(primaryGPUAddr))
  component.setPrimary("gpu",primaryGPUAddr)

-- (c) Check again whether primary GPU exists: 
  if component.isAvailable("gpu") then
    db("2(c) Primary GPU successfully changed: " .. tostring(component.gpu.address))
  else
    db("2(c) No Primary GPU!")
    db("... GPU Address = (" .. tostring(component.gpu.address) .. ")")
  end

-- 3) BIND PRIMARY GPU TO "TERMINAL" SCREEN:
  primaryScreenAddr = component.get(primaryScreenAddr) -- resolve full screen address
  local gpu = component.gpu
  db("3) Attempting Screen Bind: " .. tostring(gpu.bind(primaryScreenAddr)))

Debug Output:  

IF the boot sequence happens to randomly select the same GPU I want as my primary, everything works fine, and by debug output looks like this:

1) Mounted hard drive under '/main'
2(a) Primary GPU exists at Boot: 3f5359d7-b4a9-442b-a17d-26cef3db1e48
2( Setting Primary GPU to: 3f5359d7-b4a9-442b-a17d-26cef3db1e48
2(c) Primary GPU successfully changed: 3f5359d7-b4a9-442b-a17d-26cef3db1e48
3) Attempting Screen Bind: true

(note the address at 2(a) is the same as the desired primary GPU)

However, if the boot sequence picks one of the other two GPUs, "component.setPrimary()" apparently removes the primary GPU instead of changing it, and I get the following debug output:

1) Mounted hard drive under '/main'
2(a) Primary GPU exists at Boot: 3bdd83ae-1559-42b4-98dd-09cb46a8fb16
2( Setting Primary GPU to: 3f5359d7-b4a9-442b-a17d-26cef3db1e48
2(c) No Primary GPU!

Additionally, the following error shows up in /tmp/event.log:

boot/03 component.lua:51: no primary 'gpu' available

(I assume this error exits the code, preventing more debug messages, when I first try the "component.gpu.address" immediately after the "No Primary GPU" debug message.)

Any idea what's going on?  The fact that everything works if the desired GPU is randomly chosen at boot, suggests that the code is working, and that something is fishy with component.setPrimary().

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Ah, you're running into this problem because setting primaries is indeed not instant. I guess I forgot to document this in the wiki, terribly sorry for the confusion and lost time the caused. To solve your issue, a simple os.sleep(0.2) after your setPrimary should do the trick.

 

The reason for this behavior was to avoid the shell/term spazzing out when changing the primary gpu/screen IIRC.

Link to post
Share on other sites
  • 0

Well this is just getting weirder and weirder.  Now, setPrimary appears to randomly select the gpu.  Here is the debug output (the only change to the initial file was adding "os.sleep(0.2)" immediately after setPrimary, and adding the output of a component.list to my debug file so you can confirm I'm getting my addresses right):

COMPONENTS:
7ba654c7-9a62-4221-978e-01b9e3e13ede --- computer
98aa9c50-3f18-433f-99af-93fc83b7bbe5 --- gpu
3bdd83ae-1559-42b4-98dd-09cb46a8fb16 --- gpu
dc40b4b8-4663-4378-b4e5-2a4da339b42f --- screen
b3f856ca-8e6c-484f-9f52-bf30448736f2 --- keyboard
1a1c197d-bf4d-4b59-90e6-f6ecc3f74035 --- screen
3f5359d7-b4a9-442b-a17d-26cef3db1e48 --- gpu
e33dafce-6893-422a-b1b1-61ce080735e3 --- screen
83c65b98-76c1-44e6-8e71-0df8fbb2d681 --- filesystem
14bf0dce-d956-4c5e-baa8-f0db51cf11f8 --- filesystem

1) Mounted hard drive under '/main'
2(a) Primary GPU exists at Boot: 98aa9c50-3f18-433f-99af-93fc83b7bbe5
2( Setting Primary GPU to: 3f5359d7-b4a9-442b-a17d-26cef3db1e48
2(c) Primary GPU successfully changed: 3bdd83ae-1559-42b4-98dd-09cb46a8fb16
3) Attempting Screen Bind: true
Link to post
Share on other sites
  • 0

Sorry to bump an old thread, but I feel it's warranted - running 1.5.19.37, I still encounter this exact same issue - completely random primary screen assignment. Was wondering if you ever solved it Eunomiac? It's pretty annoying, especially since the big screen don't even have a keyboard attached. I've even tried, in the last while loop of init.lua, setting my GPU address and manually binding it and calling setPrimary() before the shell is loaded - but still occasionally the shell starts up on the second GPU/screen.

 

The behavior I have noticed, is that it works most of the time - but occassionally I will have to reboot many times in a row before the screen behavior is assigned correctly. What happens is that the boot sequence happens on the terminal screen, but then the shell incorrectly loads onto my big screen. Here is my current rc.d script (with irrelevant bits snipped out):

local event = require('event')
local component = require("component")

local gpuTermAddr = "5f4ef232-533a-49f6-bcea-e421b5f982f9"
local gpuBigAddr = "f819c2de-c8e7-49db-8ab7-6b89dbdcae75"
local screenTermAddr = "e1aa3f1b-dd0b-4771-bc40-e9995982e013"
local screenBigAddr = "e7d5ebd0-0c66-4eb2-9355-4dffe601e815"
local w, h = 96, 30
local gpu

function start(msg)
  event.listen("init", init)
end

function init()
  -- ensure force-set the primary GPU and bind it's screen
  component.proxy(gpuTermAddr).bind(screenTermAddr)
  component.setPrimary("gpu", gpuTermAddr)
  os.sleep(1)
  -- set big screen
  gpu = component.proxy(gpuBigAddr)
  gpu.bind(screenBigAddr)
  os.sleep(1)
  -- set big screen resolution
  gpu.setResolution(w, h)
  os.sleep(1)
  gpu.fill(1, 1, w, h, " ")
  event.timer(1, runtimeLoop, math.huge)
  event.timer(0.5, doTurbineSpin, math.huge) -- debug
end  

function runtimeLoop()
  -- reactor control code stripped for brevity
end


function doTurbineSpin()
  -- ASCII animation art stripped for brevity
end

Something else I've noticed, maybe related, is that the big screen sometimes remains blank if the chunk is unloaded and then loaded again, or the server restarts, all while the computer is running. This is very rare though.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.