Jump to content

resizeBrowser content visibility issue


JeViCo

Recommended Posts

First of all, browser is created via createBrowser. I've added some in-game settings to adjust browsers's width and height. Changing settings triggers resizeBrowser function with a small delays between calls (100 ms). At some random points browser's content becomes invisible until something happens in browser or it gains a focus. I've tryied to find the issue myself by doing this:
1. Using math.floor on browser size
2. Using sizes that can be devided by two
3. Using different variations of setBrowserRenderingPaused
4. Increasing delays between each call to 1s does nothing
5. Changing blend modes (cuz i'm using webbrowser as material)

The only thing that works is recreating the browser over and over again

Link to comment

Steps to reproduce:
1. Execute /createTestBrowser command
2. Try dragging scrollbar
Sample code:

local function getFakeHtml()
	iprint("ok")
	return "<html><body><h2>Hello world<h2></body></html>"
end

local browser
local size = 200

addCommandHandler("createTestBrowser", function()
	browser = createBrowser(size, size, true, false)
	setBrowserAjaxHandler(browser, "assets/index.html", getFakeHtml)

	addEventHandler("onClientBrowserCreated", browser, function ()
		loadBrowserURL(browser, "http://mta/local/assets/index.html")

		addEventHandler("onClientRender", root, function()
			dxDrawImage(200, 200, size, size, browser)
		end)
		iprint("created")
	end)
end)

addEventHandler("onClientResourceStart", resourceRoot, function()
	local scx, scy = guiGetScreenSize()
	local width, height = 200, 20
	local scroll = guiCreateScrollBar((scx - width)/2, (scy - height)/2, width, height, true, false)
	showCursor(true)

	addEventHandler("onClientGUIScroll", scroll, function()
		local scrollAmount = guiScrollBarGetScrollPosition(scroll)
		size = 200 + (scrollAmount/100 * 200)
		resizeBrowser(browser, size, size)
	end)
end)

 

Edited by JeViCo
Link to comment

The browsers content might not be fully loaded when resizeBrowser is called
Try this one

local browser
local size = 200
local newSize = size

local function getFakeHtml()
    iprint("ok")
    return "<html><body><h2>Hello world<h2></body></html>"
end

addCommandHandler("createTestBrowser", function()
    browser = createBrowser(size, size, true, false)
    setBrowserAjaxHandler(browser, "assets/index.html", getFakeHtml)

    addEventHandler("onClientBrowserCreated", browser, function ()
        loadBrowserURL(browser, "http://mta/local/assets/index.html")

        addEventHandler("onClientRender", root, function()
            if newSize ~= size then
                resizeBrowser(browser, newSize, newSize)
                size = newSize
            end
            dxDrawImage(200, 200, size, size, browser)
        end)
        iprint("created")
    end)
end)

addEventHandler("onClientResourceStart", resourceRoot, function()
    local scx, scy = guiGetScreenSize()
    local width, height = 200, 20
    local scroll = guiCreateScrollBar((scx - width)/2, (scy - height)/2, width, height, true, false)
    showCursor(true)

    addEventHandler("onClientGUIScroll", scroll, function()
        local scrollAmount = guiScrollBarGetScrollPosition(scroll)
        newSize = 200 + (scrollAmount/100 * 200)
    end)
end)

Not sure if it will solve the prob but you can give it a try

Link to comment
  • 4 weeks later...

Interesting fact. If browser have some active input with blinking caret, it'll stay there while browser's content will remain invisible. It seems to be a GUI issue.

I've managed to solve this issue in a dumb way. To make browser's content visible again you have to make it repaint itself by modifying the HTML contents, so i did this:

executeCommandHandler(browser, "document.head.innerHTML = document.head.innerHTML")

Keep in mind that your HTML should have head tag or other non important element you can work with.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...