疏忽导致易接SDK OpenGL error

来源:互联网 发布:网络文件传输协议 编辑:程序博客网 时间:2024/05/17 07:57


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

易接代码:

SFLuaAdapter.init(Cocos2dxHelper.getActivity(), new SFActionCallback() {@Overridepublic void callback(Runnable run) {AppActivity.this.runOnGLThread(run);}});

错误修改

SFLuaAdapter.init(Cocos2dxHelper.getActivity(), new SFActionCallback() {@Overridepublic void callback(Runnable run) {Cocos2dxHelper.runOnUiThread(run);}});
由于程序员的强迫症犯了,我想要的修改:

/* 易接SDK Begin */SFLuaAdapter.init(Cocos2dxHelper.getActivity(), new SFActionCallback() {@Overridepublic 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() {@Overridepublic void run() {// TODO Auto-generated method stubSFCommonSDKInterface.onInit(Cocos2dxHelper.getActivity(), new SFOfflineInitListener() {@Overridepublic void onResponse(String tag, String value) {// TODO Auto-generated method stubJSONObject jsonObject = new JSONObject();try {jsonObject.put("tag", tag);jsonObject.put("value", value);} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), false);}});}});}public static void viewMoreGames(){Cocos2dxHelper.runOnUiThread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubSFCommonSDKInterface.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() {@Overridepublic void run() {// TODO Auto-generated method stubMap<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() {@Overridepublic void onResponse(String tag, String value) {// TODO Auto-generated method stubJSONObject jsonObject = new JSONObject();try {jsonObject.put("result", luaFuncIndex);jsonObject.put("value", value);jsonObject.put("tag", tag);} catch (JSONException e) {// TODO Auto-generated catch blocke.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() {@Overridepublic void run() {// TODO Auto-generated method stubSFCommonSDKInterface.onExit(Cocos2dxHelper.getActivity(), new SFGameExitListener() {@Overridepublic void onGameExit(boolean isExit) {// TODO Auto-generated method stubJSONObject jsonObject = new JSONObject();try {jsonObject.put("result", isExit ? "exit" : "noExit");} catch (JSONException e) {// TODO Auto-generated catch blocke.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() {@Overridepublic void run() {// TODO Auto-generated method stubSFCommonSDKInterface.recharge(Cocos2dxHelper.getActivity(), price, chargeDesc, sign, new SFIPayResultListener() {@Overridepublic void onSuccess(String arg0) {// TODO Auto-generated method stubSystem.out.println("onSuccess = " + arg0);JSONObject jsonObject = new JSONObject();try {jsonObject.put("result", "success");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);}@Overridepublic void onFailed(String arg0) {// TODO Auto-generated method stubSystem.out.println("onFailed = " + arg0);JSONObject jsonObject = new JSONObject();try {jsonObject.put("result", "fail");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);}@Overridepublic void onCanceled(String arg0) {// TODO Auto-generated method stubSystem.out.println("onCanceled = " + arg0);JSONObject jsonObject = new JSONObject();try {jsonObject.put("result", "cancel");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);}});}});}public static void pay(final String payid, final int luaFunc) {Cocos2dxHelper.runOnUiThread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubSFCommonSDKInterface.pay(Cocos2dxHelper.getActivity(), payid, new SFIPayResultListener() {@Overridepublic void onSuccess(String arg0) {// TODO Auto-generated method stubSystem.out.println("onSuccess = " + arg0);JSONObject jsonObject = new JSONObject();try {jsonObject.put("result", "success");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);}@Overridepublic void onFailed(String arg0) {// TODO Auto-generated method stubSystem.out.println("onFailed = " + arg0);JSONObject jsonObject = new JSONObject();try {jsonObject.put("result", "fail");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);}@Overridepublic void onCanceled(String arg0) {// TODO Auto-generated method stubSystem.out.println("onCanceled = " + arg0);JSONObject jsonObject = new JSONObject();try {jsonObject.put("result", "cancel");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}Cocos2dxHelper.runOnGLThread(luaFunc, jsonObject.toString(), true);}});}});}}


0 0