I'm trying to finish an assignment of my CG course. I chose this repo as reference. I refactored most of the code, migrated to WebGL2 and added BVH structure from scratch to optimize object intersection and support complex triangular objects (.obj files). This is the current code: repo.
I did these on my mbp(14' m2 pro) and it works smoothly, but when I tested it on my(and my friends') windows laptops, it just throw 'context loss' error. It's weird because the webgl contexts will crush over the whole browsers until I restart the browser completely. Otherwise, if I just refresh the tab, it won't be able to initialize webgl context anymore.
After some debugging, I found that it can still work when I only keep 1~6 simple objects(sphere, cube, plane, etc.) in scene or only one mesh in scene.
I thought it was because of the RAM but I found it only occupies 300M. As for the fact that it can run well on my mac(both Edge and Safari), I think that my code doesn't have any critical error. So I assume it was caused by the browsers and platform or some other bugs in my code.
How can I figure out this? Or anyone can help?
=== further investigation ===
When I tried dubugging, I find something really odd. I wrote this somewhere (just modify pt.frag > bool intersectMesh, from intersect.intersectPos = (meshObj.model * vec4(tempIntersect.intersectPos, 1.0)).xyz; intersect.intersectNormal = normalize((meshObj.transInvModel * vec4(tempIntersect.intersectNormal,0.0)).xyz); intersect.intersectDistance = length(ray.origin - intersect.intersectPos); to intersect.intersectDistance = INF;) in my code in order to debug (On windows of course, as everything goes well on macos):
#define INF_F (1e6)
...
intersect.intersectDistance = INF_F;
...
My code just works fine. But when I used simple expression like this:
#define INF_F (1e6)
...
intersect.intersectDistance = 2.0 * INF_F;
...
The browser will crash as I described above.
I also tried const expression const float INF_F = 1e6; but the result remains the same.
I didn't even actually use intersect.intersectDistance after that line at all.
However, in other places use all most the same expression (like other xxx_xxx.intersectDistance = INF_F;), I can still use 2.0 to mult, It's just odd!
What's that mean? Is it actually a problem of platform?