Skip to content

Commit 5c6c323

Browse files
committed
weaken extra refs to ::Window objects so undefining causes destroy
1 parent c5dca65 commit 5c6c323

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

lib/PDL/Graphics/TriD.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,7 @@ keeptwiddling3d();
864864

865865
*close3d = *close3d = \&PDL::close3d;
866866
sub PDL::close3d {
867-
return if !ref $PDL::Graphics::TriD::current_window;
868-
return if !$PDL::Graphics::TriD::current_window->can('close');
869-
$PDL::Graphics::TriD::current_window->close;
867+
$PDL::Graphics::TriD::current_window = undef;
870868
}
871869

872870
sub graph_object {

lib/PDL/Graphics/TriD/GL/GLFW.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use strict;
44
use warnings;
55
use OpenGL::GLFW qw( :all );
66
use OpenGL::Modern::Helpers qw(glGetVersion_p);
7+
use Scalar::Util qw(weaken);
78

89
our @ISA = qw(PDL::Graphics::TriD::GL);
910
my ($window_seq, @fakeXEvents, %winObjects) = 0;
@@ -39,7 +40,7 @@ sub new {
3940
if ($PDL::Graphics::TriD::verbose) {
4041
print "GLFW driver: Got TriD::GL object(GLFW window ID#$self->{window_seq} " . $self->{glfwwindow} . ")\n";
4142
}
42-
$self->{winobjects}{$self->{glfwwindow}} = $window_obj; # circular ref
43+
weaken($self->{winobjects}{$self->{glfwwindow}} = $window_obj);
4344
$self;
4445
}
4546

lib/PDL/Graphics/TriD/GL/GLUT.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use warnings;
55
use OpenGL::GLUT qw( :all );
66
use OpenGL::Config;
77
use OpenGL::Modern::Helpers qw(glGetVersion_p);
8+
use Scalar::Util qw(weaken);
89

910
our @ISA = qw(PDL::Graphics::TriD::GL);
1011
my (@fakeXEvents, @winObjects);
@@ -56,7 +57,7 @@ sub _init_glut_window {
5657
if ($PDL::Graphics::TriD::verbose) {
5758
print "GLUT driver: Got TriD::GL object(GLUT window ID# " . $self->{glutwindow} . ")\n";
5859
}
59-
$self->{winobjects}->[$self->{glutwindow}] = $window_obj; # circular ref
60+
weaken($self->{winobjects}->[$self->{glutwindow}] = $window_obj);
6061
}
6162

6263
sub DESTROY {

0 commit comments

Comments
 (0)