Crash on "message sent to deallocated instance 0x606 ..." - ios4

I have the following crash in my iOS app:
* -[GSFont retain]: message sent to deallocated instance 0x606c7c0
A little bit of experimentation showed me that this crash happens with some choices of fonts and not with others.
I do not understand why and moreover it is difficult to know where the crash actually happens. I have set all the flags that I know of in XCode in order to debug this, but with no success.
I also tried "backtrace" and "display info" but both with no real success as one can see below:
(gdb) backtrace
#0 0x0149d057 in ___forwarding___ ()
#1 0x0149cf22 in __forwarding_prep_0___ ()
#2 0x00481ec7 in -[UILabel font] ()
#3 0x00483eec in -[UILabel _drawTextInRect:baselineCalculationOnly:] ()
#4 0x00481b40 in -[UILabel drawTextInRect:] ()
#5 0x0039b6eb in -[UIView(CALayerDelegate) drawLayer:inContext:] ()
#6 0x022069e9 in -[CALayer drawInContext:] ()
#7 0x022065ef in backing_callback ()
#8 0x02205dea in CABackingStoreUpdate ()
#9 0x02205134 in -[CALayer _display] ()
#10 0x02204be4 in CALayerDisplayIfNeeded ()
#11 0x021f738b in CA::Context::commit_transaction ()
#12 0x021f70d0 in CA::Transaction::commit ()
#13 0x022277d5 in CA::Transaction::observer_callback ()
#14 0x0150cfbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#15 0x014a20e7 in __CFRunLoopDoObservers ()
#16 0x0146abd7 in __CFRunLoopRun ()
#17 0x0146a240 in CFRunLoopRunSpecific ()
#18 0x0146a161 in CFRunLoopRunInMode ()
#19 0x01e60268 in GSEventRunModal ()
#20 0x01e6032d in GSEventRun ()
#21 0x0037242e in UIApplicationMain ()
#22 0x00001c62 in main (argc=1, argv=0xbfffef28) at /Users/.…../main.m:14
(gdb) display info 0x606c7c0
No symbol "info" in current context.
(gdb)
Any help would be very much appreciated.
Thanks a lot.

I have just experienced this. In my case it had to do with UITextView. I found you cannot set the text before setting the font or you get the "-[GSFont retain]: message sent to deallocated instance..." crash. This applies to UITextViews you manually create or that are created via a xib file. If you do use a UITextView in a xib file make sure you delete all the default text in the xib file for the text view because ios seems to set the text before the font when defined in a xib file.
Update.. also just ran across an incident in which a UILabel in a xib file was causing the same problem - even without default text. Not exactly sure what the problem with UILabels is but after removing the UILabels, the crash disappeared. Added the labels back a few at a time and the crash stayed away (go figure).
Hope this helps.

Related

How to get one menu item to right justify using gtkada but not the depreciated procedure

I am using GTKADA, for a small application, and wish to right justify the help menu on the menu bar.
The old way was to call Set_Right_justified on the new menu, but that is now obsolescent.
Apparantly I should be able to use Set_Hexpand, and Set_Halign to do this.
The code I am currently using is :-
with GTK.WIDGET;
procedure Add_Menu_To_Menu_Bar
( Menu_Bar : in GTK.MENU_BAR.Gtk_Menu_Bar;
Menu : in GTK.MENU.Gtk_Menu;
Label : in string;
Right_Justified : in boolean := False )
is
New_Item : GTK.MENU_ITEM.Gtk_Menu_Item;
begin
GTK.MENU_ITEM.Gtk_New( Menu_Item => New_Item,
Label => Label );
New_Item.Set_Right_Justified( Right_Justified => Right_Justified );
-- if Right_Justified then
-- -- Below is the recommended alternative to above
-- -- but dosn't work
-- New_Item.Set_Hexpand( Expand => true );
-- New_Item.Set_Hexpand_Set(Set => true );
-- New_Item.Set_Halign( Align => GTK.WIDGET.Align_End );
-- -- Below does work, but only sets a fixed margin
-- New_Item.Set_Margin_Start(Margin => 40 );
-- New_Item.Set_Margin_End(Margin => 40 );
-- -- Below effects the entire menu bar
-- Menu_Bar.Set_Hexpand(Expand => true);
-- Menu_Bar.Set_Halign(Align => GTK.WIDGET.Align_End);
-- end if;
GTK.MENU_ITEM.Show( New_Item );
GTK.MENU_ITEM.Set_Submenu( New_Item, Menu );
GTK.MENU_BAR.Append( Menu_Shell => Menu_Bar,
Child => New_Item );
end Add_Menu_To_Menu_Bar;
N.B.
1. I know that this is now considered bad practice.
2. I am not using glade
3. This is on windows 10, with the GPL 2017 versions of GTK & GPS
I have now solved this by having two menu bars, putting them in opposite sides of a Hbox, and adding the right justifed menu's to the righthand side menu bar.
However I still think this is a bit of a cludge.
N.B. The results of my attempts are shown in as comments in the code sample, basicly the obvious solution dosn't do anything...

Fl_Tree callback when FL_WHEN_RELEASE

The documentation for Fl_Tree in FLTK 1.3.4 says:
The callback() is invoked depending on the value of when()
FL_WHEN_RELEASE -- callback invoked when left mouse button is released on an item
FL_WHEN_CHANGED -- callback invoked when left mouse changes selection state
but I can't get the callback called if the mouse is released and I can't see a difference between both. Any ideas?
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Tree.H>
static void cb_(Fl_Tree*, void*)
{
printf ("callback\n");
}
int main()
{
Fl_Double_Window* w = new Fl_Double_Window(325, 325);
Fl_Tree* o = new Fl_Tree(25, 25, 255, 245);
o->callback((Fl_Callback*)cb_);
o->when(FL_WHEN_RELEASE);
o->add("foo/bar");
o->add("foo/baz");
o->end();
w->show();
return Fl::run();
}
this snippets outputs "callback" on every change, even if FL_WHEN_RELEASE is set.
If you have downloaded, the distribution, have a look at test/input.cxx and test/tree.cxx. Both have tests for the different when selections.
WHEN_CHANGED only makes sense on edit boxes, browsers and tables - you can verify the data as it is typed in. This does not happen with WHEN_RELEASE. For all other widgets, there is virtually no difference.
Edit
In order for release to fire every time, there are one of three options
Modify the source FL_Tree.cxx. Look for FL_Tree::select. Change alreadySelected to false.
If you look at the source, in the same routine, further down, it says
#if FLTK_ABI_VERSION >= 10301
If the library is built with FLTK_ABI_VERSION set to 10301, it will call the reselect but there is also a whole load of other stuff it will do when this #define is set since it affects all widgets
Comment out the #if FLTK_ABI_VERISON and corresponding #endif in FL_Tree::select.

Line numbering from text using gtk2hs

I'm working on a program that contains a text editor on it and will be used for programming (which means that the font is monospaced and has the same size in the entire text). As such, it would be useful if it were possible to see the number of each line (paragraph, not display line) at the side of the TextView widget.
In another question (GTK+ line numbering for Text View), it was said that the SourceView widget does the job, but this widget doesn't seem to exist in gtk2hs, so I'm stuck with TextView.
Does the library offer a simple solution to this problem, or do I have to do it the hard way?
The minimalist code for using a SourceView with numbered lines with Haskell and Gtk2Hs is :
import Graphics.UI.Gtk
import Graphics.UI.Gtk.SourceView
main :: IO ()
main= do
initGUI
window <- windowNew
set window [ windowTitle := "SourceView"
, windowDefaultWidth := 100
, windowDefaultHeight := 100
, windowResizable :=True ]
sview <- sourceViewNew
sourceViewSetShowLineNumbers sview True
containerAdd window sview
onDestroy window mainQuit
widgetShowAll window
mainGUI

Is it possible to use menus created with Glade in gtk2hs?

I have menus created with Glade in my gtk2hs application. Is it possible to use this in my Haskell code to write actions for each activated menu item? Is there a simple example somewhere or project on Hackage that can be used as an illustrative example?
The only menu example I was able to find http://www.muitovar.com/gtk2hs/chap7-1.html does not seem to help to work with Gtk Builder XML.
Here two examples from an application of mine. In main, I bind the GTK widgets to variables and those to callback functions that I implement in other modules.
--To load the Glade file:
gui <- builderNew
builderAddFromFile gui "myGUI.glade"
-- To close the application:
-- bind the window "mainWindow" (defined in the Glade file) to a variable
mainWindow <- builderGetObject gui castToWindow "mainWindow"
-- bind the menu item "menu_Quit" (defined in the Glade file) to a variable
mQuit <- builderGetObject gui castToMenuItem "menu_Quit"
-- bind the menu item to the GTK function "widgetDestroy"
on mQuit menuItemActivate $ widgetDestroy mainWindow
-- bind mainWindow's event "objectDestroy" to the GTK function "mainQuit"
on mainWindow objectDestroy mainQuit
-- To call a function when the user selects another menu item, say "menu_About":
-- bind the menu item to a variable
mAbout <- builderGetObject gui castToMenuItem "menu_About"
-- make the menu item show the About Dialog (defined in the Glade file)
on mAbout menuItemActivate $ do
aboutDialog <- builderGetObject gui castToDialog "aboutDialog"
set aboutDialog [ widgetVisible := True ]
dialogRun aboutDialog
set aboutDialog [ widgetVisible := False ]
You could place the do block in a function, maybe in a module where you define all your responses to GTK events:
showAboutDialog :: Builder -> IO ()
showAboutDialog gui = [insert do block here]
Then you could substitute the do block after menuItemActivate with just:
on mAbout menuItemActivate $ showAboutDialog gui
Note that I pass the Builder object to showAboutDialog because that function needs to get the dialog from the Glade file.

What can you do in ::OnInitDialog() Visual Studio 2008 C++

What can or cannot you do in ::OnInitDialog()
Visual Studio 2008 C++
I would like to write out some text on the dialog at the dialog startup. If I put the same code in a PUSH-BUTTON OnBnClicked it works. If I put it in the OnInit, it does not give me the text on the screen. I'm assuming at the OnInit, my dialog box is not completely up, so I cannot write on it?
CRect drawRect;
drawRect.left = 00; // Shifts text to right
drawRect.right = 300;
drawRect.top = 00; // How Far Down
drawRect.bottom = 300;
// Clear out any previous name
CString strBlank = "Book Name";
SSTextOut(this->GetDC(), strBlank, &drawRect, DT_LEFT);
The function I am writing to is described in
http://www.codeproject.com/KB/GDI/SSTextOut.aspx
You can't use the function SSTextOut() in OnInitDialog(). OnInitDialog() is called before your dialog is displayed, so you can't get a valid CDC inside of it (because the dialog hasn't been drawn yet).
From the looks of it, SSTextOut() is meant to be called from an OnPaint() override.

Resources