Crazy CFPreferences!
Crazy CFPreferences!
- Subject: Crazy CFPreferences!
- From: SEBESTYÉN Gábor <email@hidden>
- Date: Mon, 18 Oct 2004 13:24:41 +0200
Hi,
I actually writing (porting) a game which is mixed in Cocoa and C++ (using Core Foundation). I have a game config handler class written in c++ which uses CFPreferences API (I don't use it from Cocoa only via CF).
If I want to write to the preferences it badly crashes:
0 libobjc.A.dylib 0x908311ec objc_msgSend + 0xc
1 com.apple.CoreFoundation 0x9019cb2c CFDictionaryAddValue + 0x1f4
2 com.apple.CoreFoundation 0x901b377c CFDictionaryCreateMutableCopy + 0x1f4
3 libsilent.dylib 0x01a21374 Config::WriteInt(char*, char*, int) + 0x84 (Config.cpp:187)
4 com.PrivateMoon.Agon2 0x0003fe1c _ZN12SoundManagerD4Ev + 0x5c (SoundManager.cpp:66)
5 com.PrivateMoon.Agon2 0x0000b2ec AGON::Stop() + 0x70 (AGON.cpp:232)
And here's the code sample:
------------------------
Config::Config() {}
Config::~Config()
{
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
}
#define MY_CFSTRING(s) \
CFStringCreateWithCString( \
NULL, \
(const char *)(s), \
kCFStringEncodingISOLatin1 \
);
void Config::WriteInt(char* section, char* key, int value)
{
CFStringRef ksect = MY_CFSTRING(section); //section
CFStringRef kdict = MY_CFSTRING(key); //key in dict
CFNumberRef val = CFNumberCreate(NULL, kCFNumberIntType, &value);
CFDictionaryRef dict0 = CFPreferencesCopyAppValue(ksect, kCFPreferencesCurrentApplication);
CFMutableDictionaryRef dict;
if (dict0) {
dict = CFDictionaryCreateMutableCopy(NULL, 0, dict0); // it crashes here
CFRelease(dict0);
} else {
dict = CFDictionaryCreateMutable(NULL, 1, NULL, NULL);
}
CFDictionarySetValue(dict, kdict , val);
CFPreferencesSetAppValue(ksect, dict, kCFPreferencesCurrentApplication);
CFRelease(dict);
CFRelease(val);
CFRelease(kdict);
CFRelease(ksect);
}
------------------------
It crashes when Config wants to create a mutable copy of the dict got from preferences.
What did I do wrong? Am I missing something?
Gábor
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden