DUI Problem & Game Crash

What happened?

when i tried CreateDUI with width 1920 heigth 1080 and Destroy it loop around 400+ times
map will start glitch bug and then game crash

[    372422] [    DumpServer]                 9636/ Process crash captured. Crash dialog content:
[    372422] [    DumpServer]                 9636/ GTA5_b3258.exe!sub_1407EFA60 (0x6d)
[    372422] [    DumpServer]                 9636/ An error at GTA5_b3258.exe!sub_1407EFA60 (0x6d) caused FiveM to stop working. A crash report is being uploaded to the FiveM developers.
[    372422] [    DumpServer]                 9636/ 
[    372422] [    DumpServer]                 9636/ Legacy crash hash: blue-hot-jupiter
[    372422] [    DumpServer]                 9636/ Stack trace:
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_1407EFA60 (0x6d)
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_1407F18E0 (0x220)
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_1407FF0F4 (0x129)
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_1407FF0DC (0xf)
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_14165E3C0 (0x68)
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_141648E34 (0x257)
[    372422] [    DumpServer]                 9636/   GTA5_b3258.exe!sub_141656984 (0x6d)
[    372422] [    DumpServer]                 9636/ 
[    373594] [    DumpServer]                 9636/ Crash report service returned si-a99653773c4c47ccb23c146cc2d601bf

Reproduction steps

    local count = 0
    while true do
        count += 1
	    local duiObject = CreateDui('about:blank', 1920, 1080)
        print(count)
        while not IsDuiAvailable(duiObject) do
            Wait(100)
        end
        Wait(100)
	    DestroyDui(duiObject)
    end

Area(s)

FiveM, Natives

Specific version(s)

FiveM b3258

Additional information

1 Like

That should be expected TBH due to the performance overhead, what’s the use case you have for repeatedly creating and immediately deleting Dui’s?

I’m currently developing a farming/plant-growing system. The idea is that when a player gets close to a plant, a DUI is created and displayed for that plant. When the player moves away from the plant, the DUI is destroyed.

This means multiple DUIs can appear at the same time—only for the plants within range—and they are cleaned up when no longer needed. The issue arises when many DUIs are created and destroyed frequently as the player moves around, which seems to lead to performance issues or crashes after a certain point.

The function DestroyDui , as the name suggest should clean up everything about that dui, but some thing i have faced during my usage of DUI specially in cases where DUI is repeated, is that the usage of the DestroyDui does not even destroy the texture that was created by it, and the texture will remain and allocate that specific texture name inside the texture dictionary it was created in until the client closes fivem or the script itself restarts, there is probably more to this than the textures that is causing a severe overhead when using duis repeatedly by creating more and destroying unused ones.
my solution for this problem was instead of destroying we let duis idle until next usage, although with minimal html/css/js load to minimize the cpu/usage of their respective chromium process.
This solution also has problems, sometimes the engine itself destroys some unused duis, although its rare but it happens and the usage of IsDuiAvailable will throw an error instead of false, wrap this around a pcall and you would have a safe IsDuiAvailable to detect this :smile:
the DUIs in general have alot of issues that needs to be addressed.

Instead of creating the DUI multiple times, why not update it’s contents (show, hide, update)?

Yes, I’ve already applied the method you suggested to resolve the issue in my system. I’m mainly wondering if, in the future, when a large number of DUIs are created, this problem could still occur or not.

Thanks, Let’s hope these issues get addressed in the future.

Fixed with fix(nui/core): use raw D3D11 device for DUI by Ehbw · Pull Request #3748 · citizenfx/fivem · GitHub

2 Likes