Im sorry if this is not the right place to ask, but i cant figure out what the problem might be, and unsure wether this is an issue with OsmGpsMap or my own code.
Im trying to show an image on the map, but i need to rescale the image every time a zoom event occurs.
Whenever i call the code to rescale the image multiple times, the application runs slower and slower until it crashes with no other message than "killed".
The code for changing existing drawn GdkPixbuf with a new GdkPixbuf with correct scale based on zoom:
GdkPixbuf* heatmapImg;
OsmGpsMapImage* image;
void updateHeatmapImgScale(OsmGpsMap* map, int zoom)
{
double metersPerPixel = Util::WebMercator::metersPerPixel(model->heatmapCenter.longLat.elements[1], zoom);
double scaleX = model->metersPerPixel.elements[0] / metersPerPixel;
double scaleY = model->metersPerPixel.elements[1] / metersPerPixel;
// Create new scaled heatmap
GdkPixbuf* heatmapImgScaled = gdk_pixbuf_scale_simple(heatmapImg, model->heatmap.width * scaleX, model->heatmap.height * scaleY, GDK_INTERP_NEAREST);
// Create image to add pixbuf to if not already exists
if(!image)
{
image = osm_gps_map_image_add(OSM_GPS_MAP(map), model->heatmapCenter.longLat.elements[1], model->heatmapCenter.longLat.elements[0], heatmapImgScaled);
}
else // If image exists, update the pixbuf already being shown
{
g_object_set(image, "pixbuf", heatmapImgScaled, NULL);
}
g_object_unref(heatmapImgScaled);
}
heatmapImg is the unscaled image and is not show on the map.
In the function i first create the newly scaled heatmapImgScaled.
I check to see if the OsmGpsMapImage container exists, if it doesent i create a new OsmGpsMapImage with the scaled heatmap.
If the OsmGpsMapImage container already exists, i simply set the "pixbuf" property to the scaled heatmap.
Lastly, i unreference the scaled heatmap so that the heatmap within OsmGpsMapImage has a reference count of 1, so that the reference count drops to 0 when i set the new heatmap with g_object_set the next time the function is called.
The rest of the code (184 lines) can be found here: https://pastebin.com/8KhnSLgH . Using a non-github link as the repository is private.
I have tried commenting out gtk_main() and only calling updateHeatmapImgScale in a loop 500 times and used Valgrind to check for memory leak. Valgrinds report on memory leakage says 2,856 bytes definitely lost, 15,494 bytes indirectly lost and 5,287 bytes possibly lost. This doesent seem to be mainly a memory leak issue as these statistics dont seems bad enough for the program to crash.
Am i doing something wrong or is this an issue with OsmGpsMap?
Im sorry if this is not the right place to ask, but i cant figure out what the problem might be, and unsure wether this is an issue with OsmGpsMap or my own code.
Im trying to show an image on the map, but i need to rescale the image every time a zoom event occurs.
Whenever i call the code to rescale the image multiple times, the application runs slower and slower until it crashes with no other message than "killed".
The code for changing existing drawn GdkPixbuf with a new GdkPixbuf with correct scale based on zoom:
heatmapImg is the unscaled image and is not show on the map.
In the function i first create the newly scaled heatmapImgScaled. I check to see if the OsmGpsMapImage container exists, if it doesent i create a new OsmGpsMapImage with the scaled heatmap. If the OsmGpsMapImage container already exists, i simply set the "pixbuf" property to the scaled heatmap. Lastly, i unreference the scaled heatmap so that the heatmap within OsmGpsMapImage has a reference count of 1, so that the reference count drops to 0 when i set the new heatmap with g_object_set the next time the function is called.
The rest of the code (184 lines) can be found here: https://pastebin.com/8KhnSLgH . Using a non-github link as the repository is private.
I have tried commenting out gtk_main() and only calling updateHeatmapImgScale in a loop 500 times and used Valgrind to check for memory leak. Valgrinds report on memory leakage says 2,856 bytes definitely lost, 15,494 bytes indirectly lost and 5,287 bytes possibly lost. This doesent seem to be mainly a memory leak issue as these statistics dont seems bad enough for the program to crash.
Am i doing something wrong or is this an issue with OsmGpsMap?