Skip to content

Commit b71bf45

Browse files
committed
Fixed the nasty ExtIO crashing which had nothing to do with ExtIO
1 parent 861135e commit b71bf45

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

JavaGUI/jni/TSDRLibraryNDK.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ void read_async(float *buf, int width, int height, void *ctx) {
9999
(*jvm)->AttachCurrentThread(jvm, (void **) &env, 0);
100100

101101
if (context->pic_width != width || context->pic_height != height) {
102-
(*env)->DeleteLocalRef(env, context->obj_pixels);
103102

104-
(*env)->CallVoidMethod(env, context->obj, context->fixSize, width, height);
103+
if (context->obj_pixels != NULL) (*env)->DeleteLocalRef(env, context->obj_pixels);
105104

105+
(*env)->CallVoidMethod(env, context->obj, context->fixSize, width, height);
106106
context->obj_pixels = (*env)->GetObjectField(env, context->obj, context->fid_pixels);
107107

108108
context->pixelsize = width * height;
@@ -147,13 +147,21 @@ JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_nativeStart (JNIEnv
147147
context->fid_pixels = (*env)->GetFieldID(env, context->cls, "pixels", "[I");
148148
context->fixSize = (*env)->GetMethodID(env, context->cls, "fixSize", "(II)V");
149149
context->notifyCallbacks = (*env)->GetMethodID(env, context->cls, "notifyCallbacks", "()V");
150+
context->obj_pixels = NULL;
150151

151152
context->pic_width = 0;
152153
context->pic_height = 0;
153154
context->pixelsize = 1;
154155
context->pixels = (jint *) malloc(sizeof(jint) * context->pixelsize);
155156

156-
THROW(tsdr_readasync(&tsdr_instance, read_async, (void *) context));
157+
(*jvm)->DetachCurrentThread(jvm);
158+
159+
int status = tsdr_readasync(&tsdr_instance, read_async, (void *) context);
160+
161+
if ((*jvm)->GetEnv(jvm, (void **)&env, javaversion) == JNI_EDETACHED)
162+
(*jvm)->AttachCurrentThread(jvm, (void **) &env, 0);
163+
164+
THROW(status);
157165

158166
(*env)->DeleteGlobalRef(env, context->obj);
159167
(*env)->DeleteGlobalRef(env, context->cls);

TSDRPlugin_ExtIO/src/ExtIOPluginLoader.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "TSDRCodes.h"
33

44
#include <stdlib.h>
5+
#include <stdio.h>
56

67
// A platform independent dynamic library loader
78

TSDRPlugin_ExtIO/src/TSDRPlugin_ExtIO.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ void callback(int cnt, int status, float IQoffs, void *IQdata) {
122122
tsdr_cb(outbuf, cntvalues, tsdr_ctx, 0);
123123
}
124124

125+
char test[200];
125126
int tsdrplugin_init(const char * params) {
127+
strcpy(test, params);
128+
126129
if (outbuf == NULL) {
127130
outbuf = malloc(sizeof(float));
128131
outbuf_size = 1;
@@ -147,7 +150,9 @@ int tsdrplugin_init(const char * params) {
147150
}
148151

149152
if (source->OpenHW()) {
150-
printf("Opened %s model %s!\n", name, model); fflush(stdout);
153+
//printf("Opened %s model %s!\n", name, model); fflush(stdout);
154+
155+
//if (source->ShowGUI != NULL) source->ShowGUI();
151156

152157
// list attenuators
153158
if (source->GetAttenuators != NULL) {

TempestSDR/src/TSDRLibrary.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ void unloadplugin(tsdr_lib_t * tsdr) {
354354
tsdrplug_close((pluginsource_t *)(tsdr->plugin));
355355
free(tsdr->plugin);
356356
tsdr->plugin = NULL;
357-
printf("Unloaded plugin\n"); fflush(stdout);
358-
359357
}
360358
}
361359

@@ -374,7 +372,7 @@ int tsdr_loadplugin(tsdr_lib_t * tsdr, const char * pluginfilepath, const char *
374372

375373
tsdr->plugin = malloc(sizeof(pluginsource_t));
376374
int status = tsdrplug_load((pluginsource_t *)(tsdr->plugin), pluginfilepath);
377-
printf("Loaded plugin\n"); fflush(stdout);
375+
378376
if (status != TSDR_OK) {
379377
unloadplugin(tsdr);
380378
RETURN_EXCEPTION(tsdr, "The plugin cannot be loaded. It is incompatible or there are depending libraries missing. Please check the readme file that comes with the plugin.", status);

0 commit comments

Comments
 (0)