[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Freeing images / unblessed reference?
- From: Dan Mueth <dmueth rheo uchicago edu>
- To: gtk-app-devel-list redhat com
- Subject: Freeing images / unblessed reference?
- Date: Wed, 18 Nov 1998 20:39:38 -0600 (EST)
I am having difficulties freeing image resources. I have a simple program
(included below, using Perl-Gtk-0.4) which creates images from data using
gdk_imlib_create_image_from_data and then displays them in a Gtk Pixmap.
It does not automatically free the images and quickly uses up 30MB of RAM
after displaying 100 images. When I use gdk_imlib_destroy_image I always
get errors:
Can't call method "changed_image" on unblessed reference at junk.pl line
56
What is an "unblessed reference"? Any suggestions on how to free up these
images and avoid unblessed references would be appreciated.
Dan
---------------------------------------------------------------------
use Gtk;
use Gtk::Atoms;
init Gtk;
init Gtk::Gdk::ImlibImage;
sub do_exit {
Gtk->exit(0);
}
sub update_image {
for($it=0;$it<100;$it++) {
print "Iteration: $it\n";
if ($it % 3 eq 0) {$data="a "x40000;}
if ($it % 3 eq 1) {$data=" a "x40000;}
if ($it % 3 eq 2) {$data=" a"x40000;}
$alpha="000"x40000;
$im3 = create_image_from_data Gtk::Gdk::ImlibImage($data,$alpha,$h,$w);
$im3->changed_image();
# Render the original 24-bit Image data into a pixmap of size $w x $h
$im3->render($w, $h);
# Free up the pixmap $p3
$p3->imlib_free;
# Extract the image and mask pixmaps from the Image
$p3 = $im3->move_image();
$m3 = $im3->move_mask;
Gtk::Gdk->flush;
$mypixmap->set($p3,$m3);
# Force Gtk to update before returning to main
# For some reason, Gtk::Gdk->events_pending is always 0 even
# when the window needs to be updated, so throw in an extra
# Gtk->main_iteration;
Gtk->main_iteration;
while (Gtk::Gdk->events_pending) { Gtk->main_iteration }
}
}
sub create_main_window {
# Create main_window
$main_window = new Gtk::Window('toplevel');
$main_window->set_title("imlib_test_1");
$main_window->set_name("main window");
$main_window->set_uposition(20, 20);
$main_window->signal_connect("destroy" => \&Gtk::main_quit);
$main_window->signal_connect("delete_event" => \&Gtk::false);
$main_window->show;
$vbox = new Gtk::VBox(0, 0);
$main_window->add($vbox);
$vbox->show;
$test_label = new Gtk::Label " This is a test ";
$vbox->pack_start($test_label, 0, 0, 20);
show $test_label;
$w = 200;
$h = 200;
$data="a "x40000;
$alpha="000"x40000;
$im3 = create_image_from_data Gtk::Gdk::ImlibImage($data,$alpha,$h,$w);
$im3->render($w, $h);
$p3 = $im3->move_image();
$m3 = $im3->move_mask;
$mypixmap = new Gtk::Pixmap $p3, $m3;
$vbox->pack_start($mypixmap,0,0,20);
$mypixmap->show;
# Add a button
$capture_button = new Gtk::Button " Play ";
signal_connect $capture_button "clicked", \&update_image;
$vbox->pack_start($capture_button,1,0,0);
$capture_button->show;
Gtk::Gdk->flush;
}
create_main_window;
main Gtk;
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]