疏忽导致易接SDK OpenGL error

22 篇文章 0 订阅
4 篇文章 0 订阅


犹豫把 SFLuaAdapter 初始化OnGLThread 在GL线程中回调写成 OnUiThread了。。导致了OpenGL error 以为是易接没有在GLThread中回调。然后自己实现了一遍同样的接口。后来越想越不对翻看易接文档多次才发现他有注册 GLThread 回调。主要是以前才开始接入什么都拷贝,然后自己修改init回调。然后没在意,强迫症犯了才修改。

易接代码:

		SFLuaAdapter.init(Cocos2dxHelper.getActivity(), new SFActionCallback() {

			@Override
			public void callback(Runnable run) {
				AppActivity.this.runOnGLThread(run);
			}
		});

错误修改

		SFLuaAdapter.init(Cocos2dxHelper.getActivity(), new SFActionCallback() {

			@Override
			public void callback(Runnable run) {
				Cocos2dxHelper.runOnUiThread(run);
			}
		});
由于程序员的强迫症犯了,我想要的修改:

		/* 易接SDK Begin */
		SFLuaAdapter.init(Cocos2dxHelper.getActivity(), new SFActionCallback() {

			@Override
			public void callback(Runnable run) {
				Cocos2dxHelper.runOnGLThread(run);
			}
		});
		/* 易接SDK End */

重新实现一遍的接口,



package org.cocos2dx.lua;

import java.util.HashMap;
import java.util.Map;

import org.cocos2dx.lib.Cocos2dxHelper;
import org.cocos2dx.lib.Cocos2dxLuaJavaBridge;
import org.json.JSONException;
import org.json.JSONObject;

import com.snowfish.cn.ganga.offline.helper.SFCommonSDKInterface;
import com.snowfish.cn.ganga.offline.helper.SFExtendListener;
import com.snowfish.cn.ganga.offline.helper.SFGameExitListener;
import com.snowfish.cn.ganga.offline.helper.SFIPayResultListener;
import com.snowfish.cn.ganga.offline.helper.SFOfflineInitListener;

public class YiJieLua {
	private static boolean isInit = false;
	public static void onPause(){
		if(isInit)
			SFCommonSDKInterface.onPause(Cocos2dxHelper.getActivity());
	}
	
	public static void onDestroy(){
		if(isInit)
			SFCommonSDKInterface.onDestroy(Cocos2dxHelper.getActivity());
	}
	
	public static void onResume(){
		if(isInit)
			SFCommonSDKInterface.onResume(Cocos2dxHelper.getActivity());
	}
	
	public static void onInit(final int luaFunc) {
		if (isInit){
			return;
		}
		isInit = true;
		Cocos2dxHelper.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				SFCommonSDKInterface.onInit(Cocos2dxHelper.getActivity(), new SFOfflineInitListener() {

					@Override
					public void onResponse(String tag, String value) {
						// TODO Auto-generated method stub
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("tag", tag);
							jsonObject.put("value", value);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), false);
					}
				});
			}
		});
	}
	
	public static void viewMoreGames(){
		Cocos2dxHelper.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				SFCommonSDKInterface.viewMoreGames(Cocos2dxHelper.getActivity());	
			}
		});
	}
	
//	public static void extend(final String data, final Map<String, Integer> luaFuncs){
//		Cocos2dxHelper.runOnUiThread(new Runnable() {
//			
//			@Override
//			public void run() {
//				// TODO Auto-generated method stub
//				Map<String, SFExtendListener> sfExtendMap = new HashMap<String, SFExtendListener>();
//				for (final Map.Entry<String, Integer> entry : luaFuncs.entrySet()) {
//					sfExtendMap.put(entry.getKey(), new SFExtendListener() {
//						
//						@Override
//						public void onResponse(String tag, String value) {
//							// TODO Auto-generated method stub
//							
//							JSONObject jsonObject = new JSONObject();
//							try {
//								jsonObject.put(tag, value);
//							} catch (JSONException e) {
//								// TODO Auto-generated catch block
//								e.printStackTrace();
//							}
//							Cocos2dxHelper.runOnGLThread(entry.getValue(), jsonObject.toString(), true);
//						}
//					});
//				}
//				SFCommonSDKInterface.extend(Cocos2dxHelper.getActivity(), data, sfExtendMap);
//			}
//		});
//	}
	
	public static void extend(final String data, final int count, final int luaFunc){		
		Cocos2dxHelper.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Map<String, SFExtendListener> sfExtendMap = new HashMap<String, SFExtendListener>();
				for (int i = 0; i < count; i++) {
					final int luaFuncIndex = i;
					Cocos2dxLuaJavaBridge.retainLuaFunction(luaFunc);
					sfExtendMap.put(String.valueOf(i), new SFExtendListener() {
						
						@Override
						public void onResponse(String tag, String value) {
							// TODO Auto-generated method stub
							
							JSONObject jsonObject = new JSONObject();
							try {
								jsonObject.put("result", luaFuncIndex);
								jsonObject.put("value", value);
								jsonObject.put("tag", tag);
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
						}
					});
				}
				Cocos2dxLuaJavaBridge.releaseLuaFunction(luaFunc);
				SFCommonSDKInterface.extend(Cocos2dxHelper.getActivity(), data, sfExtendMap);
			}
		});
	}
	
	public static String getUserId(){
		return String.valueOf(SFCommonSDKInterface.getUserId());
	}

	public static boolean isPaid(String payId) {
		return SFCommonSDKInterface.isPaid(Cocos2dxHelper.getActivity(), payId);
	}

	public static void setPaid(String payId) {
		SFCommonSDKInterface.setPaid(Cocos2dxHelper.getActivity(), payId);
	}

	public static boolean isMusicEnable(){
		return SFCommonSDKInterface.isMusicEnabled(Cocos2dxHelper.getActivity());
	}
	
	public static void onExit(final int luaFunc){
		Cocos2dxHelper.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				SFCommonSDKInterface.onExit(Cocos2dxHelper.getActivity(), new SFGameExitListener() {
					
					@Override
					public void onGameExit(boolean isExit) {
						// TODO Auto-generated method stub
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", isExit ? "exit" : "noExit");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}
				});
			}
		});
	}
	
	public static void recharge(final int price, final String chargeDesc, final String sign, final int luaFunc){
		Cocos2dxHelper.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				SFCommonSDKInterface.recharge(Cocos2dxHelper.getActivity(), price, chargeDesc, sign, new SFIPayResultListener() {

					@Override
					public void onSuccess(String arg0) {
						// TODO Auto-generated method stub
						System.out.println("onSuccess = " + arg0);
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", "success");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}

					@Override
					public void onFailed(String arg0) {
						// TODO Auto-generated method stub
						System.out.println("onFailed = " + arg0);
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", "fail");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}

					@Override
					public void onCanceled(String arg0) {
						// TODO Auto-generated method stub
						System.out.println("onCanceled = " + arg0);
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", "cancel");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}
				});
				
			}
		});
	}
	
	public static void pay(final String payid, final int luaFunc) {
		Cocos2dxHelper.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				SFCommonSDKInterface.pay(Cocos2dxHelper.getActivity(), payid, new SFIPayResultListener() {

					@Override
					public void onSuccess(String arg0) {
						// TODO Auto-generated method stub
						System.out.println("onSuccess = " + arg0);
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", "success");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}

					@Override
					public void onFailed(String arg0) {
						// TODO Auto-generated method stub
						System.out.println("onFailed = " + arg0);
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", "fail");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}

					@Override
					public void onCanceled(String arg0) {
						// TODO Auto-generated method stub
						System.out.println("onCanceled = " + arg0);
						JSONObject jsonObject = new JSONObject();
						try {
							jsonObject.put("result", "cancel");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);
					}
				});
			}
		});

	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值