node inspector 太帅了

看代码方便多了

Error: Cowardly refusing to `sudo brew link`

$ sudo brew link node
Error: Cowardly refusing to `sudo brew link`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

解决办法

$ sudo chown -R root /usr/local

[转]Moving From MacPorts to Homebrew

Using MacPorts? You should really think about moving to Homebrew. Why?
  • Homebrew installs packages into their own isolated prefixes and then symlinked into /usr/local.
  • It uses the libs that are already installed, no need to compile another perl, openssl or x11 and other stuff that can be found on your mac. Don’t waste time and disc space.
  • Way better command line user interface
  • Homebrew and it’s installation scripts are hosted at Github
  • The installation scripts (aka recepies) and Homebrew itself are written in ruby.
Moving from MacPorts to Homebrew sounds a little bit scary. MacPorts has tons of compiled stuff on your system. But you can do this. Trust me :) .
 
First, uninstall MacPorts:
 
sudo port -f uninstall installed
 
Second step: remove everything that is left from MacPorts (check for MySQL and other stuff in /opt/local first) :
 
sudo rm -rf /opt/local
sudo rm -rf /Applications/DarwinPorts
sudo rm -rf /Applications/MacPorts
sudo rm -rf /Library/LaunchDaemons/org.macports.*
sudo rm -rf /Library/Receipts/DarwinPorts*.pkg
sudo rm -rf /Library/Receipts/MacPorts*.pkg
sudo rm -rf /Library/StartupItems/DarwinPortsStartup
sudo rm -rf /Library/Tcl/darwinports1.0
sudo rm -rf /Library/Tcl/macports1.0
sudo rm -rf ~/.macports
 
Alternatively you can move those directories to another place and delete them if everything is okay (if you don’t trust your Timemachine ;) ).
 
After that you should remove the /opt/local/bin from your $PATH.
 
Now install Homebrew with the command you find here.
 

Augmented Reality

最近在搞Google Glass,各种Sensor不好弄

Unity c# 空指针

在公司比较闲,让帮忙改一个奇怪的crash,没有任何log,才搞半天,发现是由于LoadLevelAsync 的Thread Loading,在乱七八糟的android机器上出现问题了,空指针,访问没有loading完的Additive场景里的东西。

下面的代码在Galaxy S4上直接crash,而且没有任何log,太恶心人了,如果项目代码一大堆,用最原始的排除法也让你累吐血

public class Boot : MonoBehaviour 
{
	class TestNULL
	{
		public void Test()
		{
			Debug.Log("########## Test");
		}
	}
	
	TestNULL _test = null;
	
	void Start () 
	{
		_test.Test(); //没有NullPointer异常?!
	}

整理了下,写了个Unity Plugin,准确定位空指针crash

void print_stack(void* ptr)
{
    ucontext_t *ucontext = (ucontext_t*)ptr;
    sigcontext& sig = ucontext->uc_mcontext;
    gprintf("reg[fp]: %p", sig.arm_fp);
    gprintf("reg[ip]: %p", sig.arm_ip);
    gprintf("reg[sp]: %p", sig.arm_sp);
    gprintf("reg[lr]: %p", sig.arm_lr);
    gprintf("reg[pc]: %p", sig.arm_pc);

    if(hasMono)
    {
        MonoDomain* domain = mono_get_root_domain();
        mono_thread_attach(domain);
        gprintf("mono trace:");
        gprintf("%s", mono_pmip((void*)sig.arm_pc));

        MonoJitInfo* jit = mono_jit_info_table_find(domain, (char*)sig.arm_pc);
        if(jit)
        {
            uint32_t code_offset = (uint32_t)((uint8_t*)sig.arm_pc - (uint8_t*)jit->code_start);
            MonoDebugSourceLocation* source = mono_debug_lookup_source_location (jit->method, code_offset, domain);
            if (source) gprintf("\t %s:%d", source->source_file, source->row);
        }
    }
}

void signal_handler(int signum, siginfo_t *info, void * ptr)
{
    if (info->si_addr == NULL) 
    {
        gprintf("================NullPointerException Begin====================");
        gprintf("\n");
        
        print_stack(ptr);
        
        gprintf("\n");
        gprintf("================NullPointerException End====================");
    } 
    else
    {
        gprintf("================UnKnownException Begin====================");
        gprintf("\n");
        
        print_stack(ptr);
        
        gprintf("\n");
        gprintf("================UnKnownException End====================");

    }
    signal(signum, SIG_DFL);
    //kill(getpid(), signum);
}

输入法加强

在Editbox中显示pingyin提示

TreeView 测试

测试了下TreeView,还不错

    control.treeView:setRootVisible(true)
    local rootNode = control.treeView:getRoot()
    
    rootNode:add(TreeNode:new("Test1"))
    rootNode:add(TreeNode:new("Test2"))
    rootNode:add(TreeNode:new("Test3"))
    rootNode:getChild(0):add(TreeNode:new("Test4"))
    rootNode:getChild(1):add(TreeNode:new("中文"))

Posix semaphore blocked by Mac Store sandbox

sem_open无法在Mac Store App中使用,会被sandbox denied,需要额外的权限,为保险起见,还是不要使用,免得被Apple拒了

以下代码无法通过

#include <semaphore.h>

sem_t * pSemaphore = sem_open(name, O_CREAT, 0777, 1);
if (pSemaphore == (sem_t *)SEM_FAILED)
{
    //... 
}

用pthread_mutex替代

#include <pthread.h>

pthread_mutex_t* pSemaphore = (pthread_mutex_t *)BL_MALLOC(sizeof(pthread_mutex_t));
int ret = pthread_mutex_init(pSemaphore, NULL);
if (ret != 0)
{
    //... 
}

导入功能什么时候取消了?

这blog真心不错,程序员量身定做:)还有这拉风的域名...

就是不知道如何导入导出文章,  开始全新的blog

UI编辑器测试

Hybrid封装,纯Lua实现,继续完善

iOS同样效果,自适应窗口

 

 

require "editor/BaseControl"
--------------------------------------------

DebugInfoControl = class("DebugInfoControl", function(parent)
    return BaseControl.create("DebugInfo.layout", parent)
end)

DebugInfoControl.__index = DebugInfoControl


function DebugInfoControl.create(parent)
    local control = DebugInfoControl.new(parent)

    control.textbox= GUICast:toTextBox(control:getWidget("_Main"))
    control.frames = 0
    control.timer = 0
    control:registerEvent("Event_Update", control.update)

    return control
end

function DebugInfoControl:update(delta)
    self.frames = self.frames+1
    self.timer = self.timer+delta
    if self.timer > 0.5 then
        self.textbox:setCaption(string.format("FPS:%d", self.frames / self.timer))
        self.frames = 0
        self.timer = 0
    end
end