In my project, I encountered a problem, the following is the phenomenon:
The problem that is hard to describe.
When I keep refreshing (F5), there’s a probability
When I change the code with(HMR Hot Module Replacement), there is also a probability that it will occur
I don’t know if this is a problem, and I’m worried that this problem will be exposed in my production environment.So I wrote a method called reloadEnv, but it doesn’t work, and the same goes for the callback onError
There was a chance that env would load but the scene would not be bright. I only used env to illuminate the scene throughout the scene
The picture below shows a mistake. The scene is dark!!!
When the problem occurs, you should try to see if the env file is loaded or not by looking in the inspector at the corresponding texture. Also, you should try to use Spector, and when the problem occurs, take a snapshot. You will see in-depth what are the parameters of the rendering of the car and see if the env texture is there.
Even more if you have the problem with a car (loading time non negligeable) and not with a cube (instant).
Keep in mind that :
loadSomeAsset(params, function(){
// on loaded Some Asset
})
loadSomeEnv(params, function(){
// on loaded Some Env
})
Here you have no clue which one triggers first. So if you have some code with the env, do be done when the asset is loaded, encapsulate the callbacks :
loadSomeAsset(params, function(){
// on loaded Some Asset
loadSomeEnv(params, function(){
// on loaded Some loadSomeEnv
})
})
Sorry by advance if I explain something absolutely obvious for you But by experience, most of “random after F5” stuffs come from non consistent code execution order, due to bad asynchronous handling
Also as a side note because you mentioned this, be aware of your code because if you have side effects , HMR is not going to always deal with these. That is where you need to rely on hooks to call into these side effect code structures manually, or you need a browser refresh. Although then we are at the other aspects of the problem. I’m pretty sure it is not an engine problem and rather some code you need to change… as @Evgeni_Popov pointed out , use the inspector to debug.
Sorry to bother you again!!
I recorded three times with SpectorJS, of which two errors were recorded, but I couldn’t see anything abnormal, because I am also a novice to SpectorJS, I can only compare and capture, and
Unfortunately, I cannot upload json files,it is too big;
Are you really sure that the problem is due to the env file not being loaded? Have you tried explicitly not loading the env file and checking whether the rendering is the same as when the problem occurs?
Unfortunately, we can’t tell what’s going on from Spector’s screenshots alone. Can you set up a live link somewhere so we can try it out for ourselves?