作者存档: nick - 第8页

图片上传测试

这几天文件上传突然不能用了,php返回错误是3,查了一圈磁盘空间,权限,配额都没发现问题,最后把apache换成nginx+phpfpm还是同样错误。这时才感觉可能是网络原因,通过ssh端口转发访问,成功上传

Mono运行c#偶发异常

写的一个负载均衡程序,在Win下运行良好,Mac和Linux下用Mono运行总会偶发一些Native异常 T.T

* Assertion at ./mono-os-mutex.h:135, condition `res != EINVAL’ not met

Stacktrace:

at <0xffffffff>
at (wrapper managed-to-native) System.Threading.Thread.SleepInternal (int) <0x00012>
at System.Threading.Thread.Sleep (int) <0x00023>
at CRI.V2.Common.JobGroup.WorkProc (int) <0x0034f>
at CRI.V2.Common.JobGroup/<>c__DisplayClass1.b__0 () <0x0001b>
at System.Threading.ThreadHelper.ThreadStart_Context (object) <0x0008e>
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) <0x001bb>
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) <0x00033>
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) <0x0005a>
at System.Threading.ThreadHelper.ThreadStart () <0x00039>
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <0x0009c>

Native stacktrace:

0 mono 0x001c03d6 mono_handle_native_sigsegv + 342
1 mono 0x002132a1 sigabrt_signal_handler + 145
2 libsystem_platform.dylib 0x9f760ebb _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 libsystem_c.dylib 0x9f5e9a5c abort + 141
5 mono 0x003771b1 monoeg_log_default_handler + 129
6 mono 0x003772ab monoeg_assertion_message + 107
7 mono 0x0036d46b mono_thread_info_sleep + 1035
8 mono 0x002af9a1 ves_icall_System_Threading_Thread_Sleep_internal + 97
9 ??? 0x005108dc 0x0 + 5310684
10 mscorlib.dll.dylib 0x0196dba4 System_Threading_Thread_Sleep_int + 36
11 ??? 0x0050eee0 0x0 + 5304032
12 ??? 0x0050e9b4 0x0 + 5302708
13 mscorlib.dll.dylib 0x0196cf3f System_Threading_ThreadHelper_ThreadStart_Context_object + 143
14 mscorlib.dll.dylib 0x0196b4ec System_Threading_ExecutionContext_RunInternal_System_Threading_ExecutionContext_System_Threading_ContextCallback_object_bool + 444
15 mscorlib.dll.dylib 0x0196b324 System_Threading_ExecutionContext_Run_System_Threading_ExecutionContext_System_Threading_ContextCallback_object_bool + 52
16 mscorlib.dll.dylib 0x0196b29b System_Threading_ExecutionContext_Run_System_Threading_ExecutionContext_System_Threading_ContextCallback_object + 91
17 mscorlib.dll.dylib 0x0196d06a System_Threading_ThreadHelper_ThreadStart + 58
18 ??? 0x0050e965 0x0 + 5302629
19 mono 0x00106487 mono_jit_runtime_invoke + 951
20 mono 0x002deb26 mono_runtime_invoke + 150
21 mono 0x002e427c mono_runtime_delegate_invoke + 92
22 mono 0x002b59f5 start_wrapper + 693
23 mono 0x0036f9bd inner_start_thread + 349
24 libsystem_pthread.dylib 0x9f76a11b _pthread_body + 184
25 libsystem_pthread.dylib 0x9f76a063 _pthread_body + 0
26 libsystem_pthread.dylib 0x9f76993e thread_start + 34

Debug info from gdb:

xcode-select: error: no developer tools were found at ‘/Applications/Xcode.app’, and no install could be requested (perhaps no UI is present), please install manually from ‘developer.apple.com’.

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

农药确实是个很不错的游戏,易上手,5岁不到的宝宝都能操作,快节奏,能随时在茶余饭后开上一局,是PC game移动化的成功案例

Gravity Field Release

优化主界面效果;
增加第3章;
parsy-core线程同步Bug修复;

2.5.2017
—————————-

0.5.2
2.15.2017

—————————-

0.5.4
2.19.2017

—————————-

调整粒子效果
0.6.1
3.29.2017

—————————-

0.6.2
4.1.2017

NSString 相关

NSString 与 std::string 互转:

NSString -> std::string
NSString* s = @”test”;
std::string str = [s UTF8String];

std::string -> NSString
std::string str = “test”;
NSString* s = [NSString stringWithCString:str.c_str() encoding:[NSString defaultCStringEncoding]];

NSString 格式化:
[NSString stringWithFormat:@”…..”, p1, p2…];

多语言:
NSLocalizedstring是系统默认的本地化它会自动取Localizable.strings里面的键值。
如果自己新建了一个的xxx.strings文件,取值的时候要用NSLocalizedStringFromTable(@”label”, @”xxx”, nil);
Localize有时候没有中文可以选,只要在目录中 cp -R en.lproj zh-Hans.lproj 复制一份,然后添加到项目中即可

Gravity Field

Gravity Field (引力谜题) 第一版已成功发到 Google Play
Cheers!
Gravity Field (Google Play)
Gravity Field (本站)

cocos2dx 3.x Android中加入AdMob

观察 AppActivity.java:
public class AppActivity extends Cocos2dxActivity
启动的Activity是继承Cocos2dxActivity;

Cocos2dxActivity 存在 mFrameLayout,那就直接在里面设置个PopupWindow即可;

Activity本身空无一物,直接加上一下代码即可:

public class AppActivity extends Cocos2dxActivity {
    private AdView adView;
    private PopupWindow popUp;
    private static AppActivity _activity;
    private LinearLayout layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        _activity = this;
        adView = new AdView(this); 
        adView.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx"); // 这里填自己的AdUnitId
        adView.setAdSize(AdSize.BANNER);
        adView.setAdListener(new AdmobListener()); // AdmobListener 中处理收到事件
    }
    public static void showHideAdPopup() { // 静态方法供Native代码调用
        _activity._showHideAdPopup();
    }
    public void _showHideAdPopup() {
        if (popUp == null) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        popUp = new PopupWindow(_activity);
                        popUp.setWidth(360);
                        popUp.setHeight(50);
                        popUp.setWindowLayoutMode(WindowManager.LayoutParams.WRAP_CONTENT,
                                WindowManager.LayoutParams.WRAP_CONTENT);
                        popUp.setClippingEnabled(false);
                        layout = new LinearLayout(_activity);
                        layout.setPadding(-10, -10, -10, -10); // 不加这句AdView可能会没有足够Size容纳加载不了
                        MarginLayoutParams params = new MarginLayoutParams(
                                LayoutParams.MATCH_PARENT,
                                LayoutParams.MATCH_PARENT);
                        params.setMargins(0, 0, 0, 0);
                        layout.setOrientation(LinearLayout.VERTICAL);
                        layout.addView(adView, params);
                        popUp.setContentView(layout);

                        AdRequest adRequest = new AdRequest.Builder()
                                .addTestDevice("xxxxxxxxxxxxxxxxxxxxxxxx") // 申明测试设备,不加乱点会被ban账号,在logcat中搜AdRequest可以看到
                                .build();
                        _activity.adView.loadAd(adRequest);

                        popUp.showAtLocation(mFrameLayout, Gravity.BOTTOM, 0, 0);
                        popUp.update();
                    } catch (Exception ex) {
                        Toast.makeText(AppActivity.this, ex.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            });
        } else { // 再次调用隐藏
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    layout.removeView(adView);
                    popUp.dismiss();
                    popUp = null;
                }
            });
        }
    }
    private class AdmobListener extends AdListener {
        @Override
        public void onAdClosed() {
            Log.d("", "Closed");
            super.onAdClosed();
        }
        @Override
        public void onAdFailedToLoad(int errorCode) {
            Log.d("", "Failed");
            super.onAdFailedToLoad(errorCode);
        }
        @Override
        public void onAdLeftApplication() {
            Log.d("", "Left");
            super.onAdLeftApplication();
        }
        @Override
        public void onAdLoaded() {
            Log.d("", "Loaded");
            super.onAdLoaded();
        }
        @Override
        public void onAdOpened() {
            Log.d("", "Opened");
            super.onAdOpened();
        }
    }
    @Override
    public void onDestroy() {
        if (adView != null) {
            adView.destroy();
        }
        super.onDestroy();
    }
}

Native 代码中通过cocos2d::JniHelper交互
记得判断CC_TARGET_PLATFORM,防止XCode编译ios时出错

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/jni/JniHelper.h"
const char* NativeActivityClassName = "org/cocos2dx/cpp/AppActivity";
#endif

void AdmobHelper::showAds() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    cocos2d::JniMethodInfo t;
    if (cocos2d::JniHelper::getStaticMethodInfo(t
                                                , NativeActivityClassName
                                                , "showHideAdPopup"
                                                , "()V"))
    {
        t.env->CallStaticVoidMethod(t.classID, t.methodID);
        t.env->DeleteLocalRef(t.classID);
    }
#endif
}

cocos2dx 单点点击事件

1、通过cocos2d::EventListenerTouchOneByOne::create()创建 listener;
2、多个listener addEventListenerWithSceneGraphPriority 按z-order顺序触发,需要自行判断点击范围;
3、onTouchBegan 中返回值为true才会触发后续Moved Ended Cancelled事件;
4、setSwallowTouches(true) 且onTouchBegan返回true时,不会触发其他的listener;

cocos2d 编译android报错解决

cocos compile 参数中要加上 –app-abi armeabi –ndk-toolchain arm-linux-androideabi-4.9

说明中app-abi默认为armeabi,实际上为arm64
ndk-toolchain根据实际情况指定版本

一天一时书计划

计划每天花一小时时间读书