Continguing fixes. Some issues with memory leaks

This commit is contained in:
Wito Wiala 2026-06-05 19:18:13 +01:00
parent 79c87a6c15
commit 63c10c6573
7 changed files with 24 additions and 25 deletions

View file

@ -41,7 +41,7 @@ impl BxDFTrait for DiffuseBxDF {
return None;
}
let mut wi = sample_cosine_hemisphere(u);
if wo.z() == 0. {
if wo.z() < 0. {
wi[2] *= -1.;
}
let pdf = cosine_hemisphere_pdf(abs_cos_theta(wi));

View file

@ -114,7 +114,7 @@ impl CameraTrait for OrthographicCamera {
Some(CameraRay {
ray: camera_ray,
weight: SampledSpectrum::default(),
weight: SampledSpectrum::new(1.),
})
}

View file

@ -58,7 +58,7 @@ impl CameraTrait for SphericalCamera {
);
Some(CameraRay {
ray: self.render_from_camera(&ray, &mut None),
weight: SampledSpectrum::default(),
weight: SampledSpectrum::new(1.),
})
}
}

View file

@ -86,7 +86,7 @@ impl From<&SubsurfaceInteraction> for SurfaceInteraction {
dvdx: 0.,
dudy: 0.,
dvdy: 0.,
shape: Ptr::from(&Shape::default()),
shape: Ptr::null(),
}
}
}

View file

@ -11,7 +11,7 @@ use crate::utils::containers::SampledGrid;
use crate::utils::math::{clamp, square};
use crate::utils::rng::Rng;
use crate::utils::transform::Transform;
use crate::{gvec_with_capacity, GVec, Ptr};
use crate::{gvec_with_capacity, leak, GVec, Ptr};
use enum_dispatch::enum_dispatch;
use num_traits::Float as NumFloat;
@ -170,7 +170,7 @@ pub struct RayMajorantSegment {
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Debug)]
pub enum RayMajorantIterator {
Homogeneous(HomogeneousMajorantIterator),
DDA(DDAMajorantIterator),
@ -191,7 +191,7 @@ impl Iterator for RayMajorantIterator {
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Debug)]
pub struct HomogeneousMajorantIterator {
called: bool,
seg: RayMajorantSegment,
@ -224,7 +224,7 @@ impl Iterator for HomogeneousMajorantIterator {
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
pub struct DDAMajorantIterator {
sigma_t: SampledSpectrum,
t_min: Float,
@ -728,20 +728,20 @@ impl Default for MediumInterface {
}
impl From<Medium> for MediumInterface {
fn from(medium: Medium) -> Self {
fn from(p: Ptr<Medium>) -> Self {
Self {
inside: Ptr::from(&medium),
outside: Ptr::from(&medium),
inside: p,
outside: p,
}
}
}
impl From<&Medium> for MediumInterface {
fn from(medium: &Medium) -> Self {
Self::from(medium.clone())
}
}
// impl From<&Medium> for MediumInterface {
// fn from(medium: &Medium) -> Self {
// Self::from(medium.clone())
// }
// }
//
impl MediumInterface {
pub fn new(inside: &Medium, outside: &Medium) -> Self {
Self {

View file

@ -9,8 +9,8 @@ use crate::core::shape::{
use crate::utils::splines::{
bound_cubic_bezier, cubic_bezier_control_points, evaluate_cubic_bezier, subdivide_cubic_bezier,
};
use crate::utils::transform::{Transform, look_at};
use crate::{Float, PI, gamma};
use crate::utils::transform::{look_at, Transform};
use crate::{gamma, Float, PI};
use crate::core::geometry::{SqrtExt, Tuple};
use crate::utils::interval::Interval;
@ -61,11 +61,10 @@ impl CylinderShape {
let di = self
.object_from_render
.apply_to_vector_interval(&Vector3fi::new_from_vector(r.d));
// Solve quadratic equation to find cylinder t0 and t1 values>>
let a: Interval = square(di.x()) + square(di.y()) + square(di.z());
let b: Interval = 2. * (di.x() * oi.x() + di.y() * oi.y() + di.z() * oi.z());
let c: Interval =
square(oi.x()) + square(oi.y()) + square(oi.z()) - square(Interval::new(self.radius));
// Solve quadratic equation to find cylinder t0 and t1 values
let a: Interval = square(di.x()) + square(di.y());
let b: Interval = 2. * (di.x() * oi.x() + di.y() * oi.y());
let c: Interval = square(oi.x()) + square(oi.y()) - square(Interval::new(self.radius));
let f = b / (2. * a);
let vx: Interval = oi.x() - f * di.x();
let vy: Interval = oi.y() - f * di.y();

View file

@ -108,7 +108,7 @@ impl SphereShape {
mem::swap(&mut t0, &mut t1);
}
if t0.high > t_max || t1.low < 0. {
if t0.high >= t_max || t1.low <= 0. {
return None;
}
let mut t_shape_hit = t0;