kasuganosoras / hologramspeed

🔢 FiveM hologram speedometer
GNU General Public License v3.0
67 stars 39 forks source link

Display an anime instead of Speedometer. #4

Open hk15msv opened 3 years ago

hk15msv commented 3 years ago

After a time of perfect display. It becomes an anime image. 3

JustJokerBH commented 3 years ago

any solution yet

kasuganosoras commented 3 years ago

Try the 1.0 version?

matahombres commented 3 years ago

For some reason this happens because the model is erased/unloaded from memory, so it does not find the loaded model, I have tried to find why it happens or when it happens. But it's such a random error that it's hard for me to reproduce it. But I have a partial solution:

RegisterCommand("resetSpeed",function(source, args)
    -- Load the hologram model
    -- Ensure the display is off before we start
    InitialiseDui()
    EnsureDuiMessage {display = false}
    RequestModel(HologramModel)
    repeat Wait(0) until HasModelLoaded(HologramModel)
end, false)

When anime display -> reload model

PD: This still happens in version 1.0.1

kasuganosoras commented 3 years ago

This issue usually happens on the roleplay server, because the RP server has lots of scripts, map mods, and high-quality car mods. Too many vertexes and faces will cause the game overload, then the game engine will try to force unload some models to reduce memory use.

And sometimes the game engine will unload the hologram model before the script replaces the texture, then...this issue happened, the script cannot replace the texture correctly, you will see the default texture (my profile picture).

@matahombres code is a temporary solution, but we still need to find a way to detect the texture is replaced successfully or not. When the replacement failed it should try to replace again automatically until the replacement is finished.

panki27 commented 3 years ago

This happens on my rather small server aswell, after some time of testing. Maybe calling HAS_MODEL_LOADED and REQUEST_MODEL can help out?

matahombres commented 3 years ago

This happens on my rather small server aswell, after some time of testing. Maybe calling HAS_MODEL_LOADED and REQUEST_MODEL can help out?

No, the problem is not the model. As it is a model that "waits to be loaded", fivem/gta loads it and then unloads it and so on continuously so as not to have the model in memory.

When the model is loaded and unloaded the texture that is replaced is lost. This the line that is responsible for replacing the texture

Basically: If you put this line right below the

repeat.... until IsVehicleEngineOn(currentVehicle)

This line.

The problem will no longer appear. But I don't know to what extent it loses optimization @kasuganosoras


In short, the model is always loaded and there is no way to check if the current texture is "x".

panki27 commented 3 years ago

In short, the model is always loaded and there is no way to check if the current texture is "x".

This appears to be the case, but it might be possible to create a hacky workaround with GET_RUNTIME_TEXTURE_HEIGHT and GET_RUNTIME_TEXTURE_WIDTH.

If the anime girl has a different resolution than the speedo, this could indicate that the texture has unloaded. What do you think of this? I'd implement this, but I can't reproduce the issue consistently.

matahombres commented 3 years ago

It would be nice... But it makes no difference, the html contains everything, and size texture is same (512px) image.

The only difference is the content itself