Page 1 of 1

nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 4:29
by Major Cooke
So apparently this can happen.
Spoiler: nullptr traces
1. Grab D4D here http://forum.zdoom.org/viewtopic.php?f=19&t=52164
2. Give D4Chaingun + SovietToken + SovietActive
3. Chasecam on
4. Start firing. Bam.

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 7:58
by Graf Zahl
Yes, of course this can happen. With the chasecam on there is no viewactor. And even disregarding that, the viewactor's position is not necessarily the actual camera position for the current frame. If you want to do checks against the camera, do not check against ViewActor but against ViewPos. And you should check the actual rendering values, not the actor they are derived from. This also needs to take into account what pivot you are using for rotation.

Essentially the code to determine flipping does not look correct at all. What this really needs to do is to check is that the actual camera point (ViewPos) is above or below the tilted sprite. To be honest, I have no clue what you are actually doing there.

Which also begs the question: Why is the 'noflip' check only present for flat sprites and not for wall sprites?

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 13:24
by Major Cooke
Graf Zahl wrote:Yes, of course this can happen. With the chasecam on there is no viewactor. And even disregarding that, the viewactor's position is not necessarily the actual camera position for the current frame. If you want to do checks against the camera, do not check against ViewActor but against ViewPos. And you should check the actual rendering values, not the actor they are derived from. This also needs to take into account what pivot you are using for rotation.
I'm not sure what you mean by actual rendering values. Do you mean things similar to how the billboard sprites are handled using xcenter and all?
Graf Zahl wrote:Essentially the code to determine flipping does not look correct at all. What this really needs to do is to check is that the actual camera point (ViewPos) is above or below the tilted sprite. To be honest, I have no clue what you are actually doing there.
And I'm honestly just as confused as you are, because I didn't do most of this work. I simply maintained it for the people who made it (although the noflip is my fault).
Graf Zahl wrote:Which also begs the question: Why is the 'noflip' check only present for flat sprites and not for wall sprites?
When I last tried it a while ago, I think it did something to the decals. I'll check again to see if that's still the case.

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 13:57
by Graf Zahl
Major Cooke wrote:
Graf Zahl wrote:Yes, of course this can happen. With the chasecam on there is no viewactor. And even disregarding that, the viewactor's position is not necessarily the actual camera position for the current frame. If you want to do checks against the camera, do not check against ViewActor but against ViewPos. And you should check the actual rendering values, not the actor they are derived from. This also needs to take into account what pivot you are using for rotation.
I'm not sure what you mean by actual rendering values. Do you mean things similar to how the billboard sprites are handled using xcenter and all?
It's actually quite simple:

You are using the playsim position of the camera and the actor being rendered.
But what needs to be used is the actual view position and the interpolated actor position (and no portal offsetting, that's already factored in.)
It also needs to consider if a sprite is rotated around its center or its pivot.

Right now, by looking at the code that decides the flipping, I can't make any sense of it.

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 15:20
by Major Cooke
ViewPos - actor->Pos() then? I'm assuming by not including portals you mean not to use PosRelative.

I'll make sure to factor in the pivot/center as well.

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 15:38
by Graf Zahl
No, not even that. You have to take the position from the GLSprite. But about the formula itself I can't help you, I have no idea what it actually does.

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 16:20
by Major Cooke
Alright, I think I managed to fix most of it. Now I just need to factor in the actor's pitch.

However, there's still something else that's been around for a while. This only happens whenever there's 3D floors or complex map geometry around:
Spoiler: Image
That splitting issue has been prevalent especially with camera facing sprites and has been existing from said cam-facing sprites introduction.

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 16:40
by Major Cooke
Also I forgot to mention, DONTFLIP is already taken into account for the wallsprites.

Code: Select all

else if (spritetype == RF_WALLSPRITE)
				{
					mat.Rotate(0, 1, 0, 0);
					if (drawRollSpriteActor)
					{
						if (useOffsets)	mat.Translate(xx, zz, yy); //Handled here
						mat.Rotate(yawvecX, 0, yawvecY, rollDegrees);
						if (useOffsets) mat.Translate(-xx, -zz, -yy); //And here
					}
				}
Alright... All I need to do now is factor in the actor's pitch somehow...

Re: nullptr crash with FLATSPRITES

Posted: Thu Jul 21, 2016 19:16
by Major Cooke
https://github.com/coelckers/gzdoom/pull/60

This fixes the crash at least. I've been trying to flip the sprite appropriately with pitch inclusion, but I've had no luck so far. So for now it's still just the angle at the moment.

I'll keep trying but I do suggest the crash fix go in ASAP.