Skip to content

Commit 7fa0218

Browse files
committed
GObject::DESTROY to only call GL funcs if IDs defined
1 parent 4b03644 commit 7fa0218

File tree

1 file changed

+8
-4
lines changed
  • lib/PDL/Graphics/TriD

1 file changed

+8
-4
lines changed

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,16 @@ sub togl {
262262
sub DESTROY {
263263
my ($this) = @_;
264264
print "DESTROY $this\n" if $PDL::Graphics::TriD::verbose;
265-
my $bound = glGetIntegerv_p(GL_ARRAY_BUFFER_BINDING);
266265
my @array_bufs = grep defined, @{ $this->{Impl} }{qw(vert_buf color_buf norm_buf texc_buf)};
267-
glBindBuffer(GL_ARRAY_BUFFER, 0) if grep $bound == $_, @array_bufs;
268-
$bound = glGetIntegerv_p(GL_ELEMENT_ARRAY_BUFFER_BINDING);
266+
if (@array_bufs) {
267+
my $bound = glGetIntegerv_p(GL_ARRAY_BUFFER_BINDING);
268+
glBindBuffer(GL_ARRAY_BUFFER, 0) if grep $bound == $_, @array_bufs;
269+
}
269270
my @elt_bufs = grep defined, @{ $this->{Impl} }{qw(indx_buf)};
270-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) if grep $bound == $_, @elt_bufs;
271+
if (@elt_bufs) {
272+
my $bound = glGetIntegerv_p(GL_ELEMENT_ARRAY_BUFFER_BINDING);
273+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) if grep $bound == $_, @elt_bufs;
274+
}
271275
glDeleteBuffers_p(@array_bufs, @elt_bufs) if @array_bufs + @elt_bufs;
272276
if (defined(my $tex_id = $this->{Impl}{tex_id})) {
273277
glBindTexture(GL_TEXTURE_2D, 0) if glGetIntegerv_p(GL_TEXTURE_BINDING_2D) == $tex_id;

0 commit comments

Comments
 (0)